【发布时间】:2012-01-12 00:08:00
【问题描述】:
我正在制作一个 iPad SplitView 应用程序,其中左侧有 MasterView 表(横向),右侧有 DetailView(到目前为止没有什么新东西......)。当我单击表格单元格时,detailView 会显示单元格详细信息。 我在 detialView 上还有一个按钮可以向前移动到下一个单元格,还有一个按钮可以向后移动到上一个单元格。
我的问题是,每次单击按钮时,我都想更改左侧表格视图中的单元格选择,以便用户知道他当前所在的单元格。
我尝试调用 tableView: didSelectRowAtIndexPath: 方法,但我似乎无法正确设置 NSIndexPath(我想发送一个整数来指示下一个单元格的编号)。
这里是调用 selectRowAtIndexPath: 方法的代码:
iPadHelloWorldAppDelegate 是 AppDelegate。 masterViewController 是主控制器,上面有表格。
// method to set the image for the previous letter
-(IBAction)previousLetter{
iPadHelloWorldAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSLog(@"IndexOfImage equals: %@", appDelegate.indexOfImage);
int number = [[appDelegate.indexOfImage substringFromIndex:5] intValue];
NSString *imageName = [NSString stringWithFormat:@"image%@.png",[NSString stringWithFormat:@"%d", number-1]];
[self.letterImageView setImage:[UIImage imageNamed:imageName]];
NSLog(@"Image name: %@", imageName);
appDelegate.indexOfImage = [imageName substringToIndex:6];
NSIndexPath *currentPath = appDelegate.currentPath;
NSIndexPath *nextPath = [NSIndexPath indexPathForRow:currentPath.row-1 inSection:currentPath.section];
[masterViewController.tableView selectRowAtIndexPath:nextPath animated:YES scrollPosition:UITableViewScrollPositionNone];
NSLog(@"currentPath: %@", currentPath);
appDelegate.currentPath = nextPath;
NSLog(@"nextPath: %@", nextPath);
请帮忙...
【问题讨论】:
-
Here 是您的问题得到解决的地方。应该正是您正在寻找的。span>
-
嗨,感谢您的回答,但我已经尝试过了,并且 selectRowAtIndexPath 甚至不会像其他人那样突出显示该行。你的意思是哪个答案?第一个使用“doSomeThing”方法? didSelectRowAtIndex 对我也不起作用...
标签: xcode uitableview ipad