需要關於for循環的幫助,我還沒有完全弄清楚。過了很長時間,我想我應該轉向專家。For Loop將存儲行的附件圖標存儲到陣列
我需要這個遍歷每個索引路徑並檢查附件圖標。如果它是複選標記,請將其添加到數組中,最後記錄數組。
這一切都與一個按鈕操作綁定。這裏是代碼:
//Handles tableView row selection and addition and removal of the checkmark
- (void)tableView:(UITableView *)theTableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[theTableView deselectRowAtIndexPath:[theTableView indexPathForSelectedRow] animated:NO];
UITableViewCell *cell = [theTableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
//Reflect selection in data model
} else if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
//Reflect deselection in data model
}
}
//Sends checkmarked items to console log
- (IBAction)sendResults:(id)sender {
NSMutableArray *aList = [[NSMutableArray alloc] init];
//This is the part that isn't quite right
for (NSIndexPath *indexPath in _tableView.indexPathsForSelectedRows) {
NSString *r = [NSString stringWithFormat:@"%li",(long)indexPath.row];
[aList addObject:r];
}
NSLog(@"Selected Items: %@", _aList);
}
我認爲問題是沒有我的表格視圖單元格被選中。在我的didSelectRowAtIndexPath
方法中,我將附件圖標檢查爲複選標記,但似乎取消選中該行。所以當我登錄時我在_tableView.indexPathsForSelectedRows
沒有任何對象(我在日誌中得到「Selected Items:(null)」。
這個問題很有意義,但我似乎無法解決這個問題。 ?謝謝!
您在檢查附件類型之前取消選擇該行 – Joshua