我正在創建一個基於TableView的應用程序。 tableView正在加載XML提要的外部最後12項內容。這一切都很完美。從UITableView保存項目
所以現在我想創建一個額外的「保存喜歡的項目功能」。有2種方式來實現這一目標:
1.定製AccessoryButton
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
2(定製)編輯的tableview
if ([self.tableView isEditing])
我的問題是:你更喜歡哪一個選項你能舉出一個如何實現這個目標的例子嗎?
任何認真的答覆將不勝感激。
謝謝你的回答。由於馬特我用下面的代碼固定它:
NSMutableDictionary *item = [dataArray objectAtIndex:indexPath.row];
BOOL checked = [[item objectForKey:@"checked"] boolValue];
//cell.backgroundColor = [UIColor clearColor];
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
UIImage *image = (checked) ? [UIImage imageNamed:@"first.png"] : [UIImage imageNamed:@"second.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, image.size.width, image.size.height);
button.frame = frame;
[button setBackgroundImage:image forState:UIControlStateNormal];
[button addTarget:self action:@selector(checkButtonTapped:event:) forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColor clearColor];
cell.accessoryView = button;
正如你可以通過IM使用dataAray現在看到。我也使用存儲「檢查布隆」的plist。 (根據plist中)
- 對號不放在正確的:這不能正常工作,因爲。
所以我想創建一個存儲所選項目的Id的數組。然後遍歷數組以查看數組中是否存在ID。如果是:Star如果不是:graystar。
您認爲這是一個很好的解決方案嗎?
你是什麼意思用:itemClass? – Foo
這就是你爲你的物品創建的任何課程。 – Matt