无法使用accessoryButtonTappedforRowWithIndexPath在我的StoryBoard中工作

时间:2012-09-05 16:24:59

标签: iphone objective-c ios5

令人震惊,此问题仍未解决(9/25/12)。在我的多本书和其他有经验的iOS开发人员中就此问题进行了研究。我本以为添加pushViewController代码会修复它但没有解决方法。如果有人可以帮助我,请告诉我?如果任何人都知道对此问题的回答,那么这个问题仍然存在。

我正在尝试为我的应用程序中的accesoryButtonTappedRowWithIndexPath方法构建代码,但我无法找到如何,当您单击每个单独的披露按钮时,它会转到新的UI视图窗口。我买了几本书,比如Beginning IOS 5 Development。在“表视图”部分中,我看到了一个如何完成它的示例,但我似乎无法将它发送到我的视图中。这是我现在列出的代码。当我选择公开按钮来证明它正在工作时,我试图显示“消息”的消息类没有拉起来。我看到它可以从书中的代码中访问,但我不能让它在我的工作中,所以我可以让它进入下一个视图。有人可以帮助我吗?下面的屏幕显示,当您单击表格的单元格时,我的其他方法操作正常,因为消息提醒弹出正常。

非常感谢。

3rd 2nd 1st nbhoodcontroller_push ns_log

- (void)tableView:(UITableView *)tableView 
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{


if (NbhoodDetailController == nil) 
{
    NbhoodDetailController = [[LWWDisclosureDetailController alloc]initWithNibName:@"LWWDisclosureDetail" bundle:nil];

}
NbhoodDetailController.title = @"Getting Neighborhood Details";
NSUInteger row = [indexPath row];
NSString *SelectedNeighborhood = [ListBlocks objectAtIndex:row];
NSString *DetailMessage = [[NSString alloc]
                           initWithFormat:@"You pressed the button for the Neighborhood   %@ to invest in.", SelectedNeighborhood];
NbhoodDetailController.title = SelectedNeighborhood;
NbhoodDetailController.message = DetailMessage;// <-- the "message" class isn't accessible for some reason as well so I can click on the disclosure button and give a message.

以下索引代码行的单元格:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath//returns instances of the UITableViewCell class rows that have to     be populated into the table view.  
{
static NSString *NeighborhoodDBListCellIdentifier = @"NeighborhoodDBListCellIdentifier";

UITableViewCell *cell = [tableView    dequeueReusableCellWithIdentifier:NeighborhoodDBListCellIdentifier];//as table view cells   scroll off the screen, they are placed into a queue of cells available to be reused. So im   using those cells for the new rolls that scroll on the screen to assign them to.

if(cell == nil)//in case of no spare reuseable cells we create new ones here. If   dequeueReusableCellWithIdentifier doesn't have any to spare.
{
    cell = [[UITableViewCell alloc]
            initWithStyle:UITableViewCellStyleDefault 
            reuseIdentifier:NeighborhoodDBListCellIdentifier];
}
//assigning the images for the rows and also the disclosure buttons for each row
UIImage *image = [UIImage imageNamed:@"rowControlsIcon.png"];
cell.imageView.image = image;
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;


NSUInteger row = [indexPath row];
cell.textLabel.text = [ListBlocks objectAtIndex:row];//the output results of what the    cell is goes to the textLabel in the TableViewCell as text.  Like "Armour Neighhborhood"

return cell;


}

example of how I have the segue working for another one of my screens that switch over fine

3 个答案:

答案 0 :(得分:0)

仅创建要显示的新控制器是不够的。您还必须在accessoryButtonTappedForRowWithIndexPath:方法的末尾将其传递给导航控制器,如下所示:

[self.navigationController pushViewController:NbhoodDetailController
                                     animated:YES];

答案 1 :(得分:0)

打破早期的评论主题...我认为你的问题在于你的控制器的创建。而不是:

NbhoodDetailController = [[LWWDisclosureDetailController alloc]
    initWithNibName:@"LWWDisclosureDetail"
    bundle:nil];

这样做:

NbhoodDetailController = [[LWWDisclosureDetailController alloc]
    initWithNibName:@"LWWDisclosureDetail"
    bundle:[NSBundle mainBundle]];

这只是猜测,真的。通过逐步查看实际成功创建的内容会很有趣。

答案 2 :(得分:0)

使用故事板时,需要使用实例化视图控制器  您的UIStoryboard上的- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier

示例:

// if your storyboard file name is MainStoryboard_iPhone.storyboard then use @"MainStoryboard_iPhone" as the parameter
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
                                                     bundle:[NSBundle bundleForClass:[self class]]];
NbhoodDetailController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"Your view controller identifier"];
// You need to set the view controller identifier in IB

然后你可以把它推到导航堆栈

[self.navigationController pushViewController:viewController animated:YES];

另一种方法是使用segue。