【发布时间】:2013-07-17 15:10:29
【问题描述】:
我有一个 iPad 应用程序(XCode 4.6、ARC、Storyboards、iOS 6.2.3)。我有一个带有 21 行的 UITableView 的 UIPopover。我可以在所有行中随机设置 accessoryType,但只有在前 12 行中,accessoryType 设置(复选标记)才会持续存在,因此可以用另一种方法检查它处理。我看不出前 12 行和后 9 行之间有任何区别。 UITableView 是可滚动的,所以要到达第 11 行之后的行,你必须滚动到底部
这里是设置accessoryType的代码:
#pragma mark didSelectRowAtIndexPath
- (void) tableView:(UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath {
// get the cell that was selected
UITableViewCell *theCell = [tableView cellForRowAtIndexPath:indexPath];
if(theCell.accessoryType != UITableViewCellAccessoryCheckmark)
theCell.accessoryType = UITableViewCellAccessoryCheckmark;
else
theCell.accessoryType = UITableViewCellAccessoryNone;
}
这是我检查 accessoryType 并对其进行处理的代码:
-(void) moveServices { // (moves checked tableViewRows to services tableview)
NSMutableString *result = [NSMutableString string];
for (int i = 0; i < [servicesArray count]; i++) {
NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:0];
[tvServices scrollToRowAtIndexPath:path atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
UITableViewCell *cell = [tvServices cellForRowAtIndexPath:path];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
[result appendFormat:@"%@, ",cell.textLabel.text];
NSLog(@"\n\ni: %d\ncell.accessoryType: %d\ncell.textLabel: %@",i,cell.accessoryType, cell.textLabel);
}
}
if (result.length > 2) { // move to text box in main menu
storeServices =[result substringToIndex:[result length] - 2];
}
}
【问题讨论】:
标签: objective-c uitableview ios6