将 NEXT 按钮添加到 iPad UISplitViewControl
简单的问题(是的,对!)。我想在我的 iPad 项目的 UISplitViewController 的详细信息页面上添加一个“NEXT”按钮。如果单击,这将是前进到页面列表中的下一页的另一种方式。作为奖励,我想突出显示根视图中与您登陆的新视图相对应的正确行。
任何关于去哪里的一般指导和建议都很棒!
更新:感谢下面安娜的建议,这是我用来将所有这些整合在一起的代码。效果很好。谢谢安娜。
在详细信息页面上,我包含了以下内容:
- (IBAction)goToNext{
NSLog(@"Going to Next from Welcome");
[[NSNotificationCenter defaultCenter]
postNotificationName:@"NextPageRequested" object:nil];
}
在 RootViewController 页面上,我做了:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(moveOnToNextPage:)
name:@"NextPageRequested" object:nil];
}
最后在 RootViewController 中:
#pragma mark -
#pragma mark The NEXT Button
// This is the Code used for the Big NEXT button. basically a Notification Center listener is set up in the view did load and when triggered by any of the buttons, this
// function is called. Here, I do 3 things: 1. advance the highlighted cell of the master table view. 2. call the didSelectRowAtIndexPath function of the table to
// advance to the next page. and 3. Exchange the "dash" icon with the "check" icon.
-(void)moveOnToNextPage:(NSNotification*)notifications {
NSIndexPath* selection = [self.tableView indexPathForSelectedRow]; // grab the row path of the currently highlighted item
// Change the icon in the current row:
NSString *checkImage = [[NSBundle mainBundle] pathForResource:@"checkGreen" ofType:@"png"];
UIImage *checkMark = [[[UIImage alloc] initWithContentsOfFile:checkImage] autorelease]; // Grab the checkmark image.
if (selection) {
NSLog(@"not nil");
UITableViewCell *cell1 = [self.tableView cellForRowAtIndexPath:[self.tableView indexPathForSelectedRow]];
// cell1.accessoryType = UITableViewCellAccessoryCheckmark; // this is yet another way to add the checkmar, but for now, I will use Mine.
cell1.imageView.image = checkMark; // now set the icon
} else {
NSLog(@"must be nil");
NSUInteger indexArrBlank[] = {0,0}; // now throw this back into the integer set
NSIndexPath *blankSet = [NSIndexPath indexPathWithIndexes:indexArrBlank length:2]; // create a new index path
UITableViewCell *cell0 = [self.tableView cellForRowAtIndexPath:blankSet];
// cell1.accessoryType = UITableViewCellAccessoryCheckmark; // this is yet another way to add the checkmar, but for now, I will use Mine.
cell0.imageView.image = checkMark; // now set the icon
}
// Highlight the new Row
int nextSelection = selection.row +1; // grab the int value of the row (cuz it actually has both the section and the row {section, row}) and add 1
NSUInteger indexArr[] = {0,nextSelection}; // now throw this back into the integer set
NSIndexPath *indexSet = [NSIndexPath indexPathWithIndexes:indexArr length:2]; // create a new index path
[self.tableView selectRowAtIndexPath:indexSet animated:YES scrollPosition:UITableViewScrollPositionTop]; // tell the table to highlight the new row
// Move to the new View
UITableView *newTableView = self.tableView; // create a pointer to a new table View
[self tableView:newTableView didSelectRowAtIndexPath:indexSet]; // call the didSelectRowAtIndexPath function
//[newTableView autorelease]; //let the new tableView go. ok. this crashes it, so no releasing for now.
}
Simple question (yeah right!). I want to add a "NEXT" button on the detail pages of my UISplitViewController for my iPad project. If clicked, it would be another way of advancing to the next page in the list of pages. As a bonus, I want to highlight the correct row that in the root view that corresponds with the new view you land on.
Any general guidance and suggestions on where to go would be AWESOME!
UPDATE: Thanks to Anna's Suggestion below, here is the code I used to pull all this together. IT WORKS GREAT. Thanks Anna.
On the details page I included this:
- (IBAction)goToNext{
NSLog(@"Going to Next from Welcome");
[[NSNotificationCenter defaultCenter]
postNotificationName:@"NextPageRequested" object:nil];
}
On the RootViewController page I did:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self selector:@selector(moveOnToNextPage:)
name:@"NextPageRequested" object:nil];
}
And Finally later in the RootViewController:
#pragma mark -
#pragma mark The NEXT Button
// This is the Code used for the Big NEXT button. basically a Notification Center listener is set up in the view did load and when triggered by any of the buttons, this
// function is called. Here, I do 3 things: 1. advance the highlighted cell of the master table view. 2. call the didSelectRowAtIndexPath function of the table to
// advance to the next page. and 3. Exchange the "dash" icon with the "check" icon.
-(void)moveOnToNextPage:(NSNotification*)notifications {
NSIndexPath* selection = [self.tableView indexPathForSelectedRow]; // grab the row path of the currently highlighted item
// Change the icon in the current row:
NSString *checkImage = [[NSBundle mainBundle] pathForResource:@"checkGreen" ofType:@"png"];
UIImage *checkMark = [[[UIImage alloc] initWithContentsOfFile:checkImage] autorelease]; // Grab the checkmark image.
if (selection) {
NSLog(@"not nil");
UITableViewCell *cell1 = [self.tableView cellForRowAtIndexPath:[self.tableView indexPathForSelectedRow]];
// cell1.accessoryType = UITableViewCellAccessoryCheckmark; // this is yet another way to add the checkmar, but for now, I will use Mine.
cell1.imageView.image = checkMark; // now set the icon
} else {
NSLog(@"must be nil");
NSUInteger indexArrBlank[] = {0,0}; // now throw this back into the integer set
NSIndexPath *blankSet = [NSIndexPath indexPathWithIndexes:indexArrBlank length:2]; // create a new index path
UITableViewCell *cell0 = [self.tableView cellForRowAtIndexPath:blankSet];
// cell1.accessoryType = UITableViewCellAccessoryCheckmark; // this is yet another way to add the checkmar, but for now, I will use Mine.
cell0.imageView.image = checkMark; // now set the icon
}
// Highlight the new Row
int nextSelection = selection.row +1; // grab the int value of the row (cuz it actually has both the section and the row {section, row}) and add 1
NSUInteger indexArr[] = {0,nextSelection}; // now throw this back into the integer set
NSIndexPath *indexSet = [NSIndexPath indexPathWithIndexes:indexArr length:2]; // create a new index path
[self.tableView selectRowAtIndexPath:indexSet animated:YES scrollPosition:UITableViewScrollPositionTop]; // tell the table to highlight the new row
// Move to the new View
UITableView *newTableView = self.tableView; // create a pointer to a new table View
[self tableView:newTableView didSelectRowAtIndexPath:indexSet]; // call the didSelectRowAtIndexPath function
//[newTableView autorelease]; //let the new tableView go. ok. this crashes it, so no releasing for now.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实现此目的的一种方法是使用 NSNotificationCenter。
viewDidLoad 中的根视图控制器将调用 addObserver:selector:name:object: 来使自己成为名为 @"NextPageRequested" 的通知的观察者。
点击详细信息视图上的按钮时,将调用 postNotificationName:object: 来请求根视图控制器转到下一页。
在根视图控制器中,通知处理程序方法将(假设根视图控制器是 UITableView):
indexPathForSelectedRow
获取当前索引路径selectRowAtIndexPath:animated: scrollPosition:
要突出显示该行tableView:didSelectRowAtIndexPath:
)One way to implement this is using
NSNotificationCenter
.The root view controller, in viewDidLoad, would call
addObserver:selector:name:object:
to make itself an observer for a notification named, say, @"NextPageRequested".The button(s) on the detail view(s), when tapped, would call
postNotificationName:object:
to request the root view controller to go to the next page.In the root view controller, the notification handler method would (assuming the root view controller is a UITableView):
indexPathForSelectedRow
selectRowAtIndexPath:animated:scrollPosition:
to highlight that rowtableView:didSelectRowAtIndexPath:
directly)为您的详细视图控制器提供一个父导航控制器,并通过导航项将下一个按钮添加到导航栏。按“下一步”将触发导航堆栈的推送视图控制器。
或者将顶部工具栏添加到当前视图控制器并将按钮放在那里。
Give your detailviewcontroller a parent navigationcontroller and add your next button to the navbar via the navigation item. Pressing Next will trigger a pushviewcontroller to the nav-stack.
Or add a top-toolbar to your current view controller and put the button there.