为了解释这个问题,我在里面ViewControllerA
有一个UITableView
调用。commentTableView
从commentTableView
我开始,ViewControllerB
但我需要添加一个UITableView
名为mentionedFriendTable
to的附加项ViewControllerA
。但是一旦我添加mentionFriendTable
了,我就开始遇到导致应用程序崩溃的表问题。
我遇到的问题
我决定将其commentTableView
放入另一个名为justCommentsTable
a的类中UITableViewController class
,并将该类添加到ViewController
. 我必须分到commentTableView
不同的班级,而不是mentionFriendTable
因为mentionFriendTable
需要ViewControllerA
。几个小时后,我终于让它工作了。但是现在我最初不得不做的那个segueViewControllerB
不起作用,并且崩溃说
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<justCommentsTable: 0x21032160>) has no segue with identifier 'segueToViewControllerB'
我的故事板
在我的故事板上,我有ViewControllerA
一个内部,我在下面的代码中将totableView
链接起来,
我解释了如何变成fromtableview
@property (strong, nonatomic) IBOutlet UITableView *commentTable;
commentTable
tableview
justCommentsTable
我知道我遇到了这个崩溃,因为ViewControllerB
连接到ViewControllerA
通过MainStoryboard.storyboard
而不是justCommentsTable
我的问题
有没有办法仍然从不同类中ViewControllerA
传递ViewControllerB
和传递数据commentTableView
。
我将继续放置我发现与该问题相关的任何代码。只要告诉我我是否遗漏了任何关键代码。
ViewControllerA.h
#import "justCommentsTable.h"
@interface ViewControllerA : UIViewController<UITableViewDelegate, UITableViewDataSource>{
// in justCommentsTable.m I add this controller to the view
justCommentsTable *commentsController;
}
// this is the table that is link up in storyboard
@property (strong, nonatomic) IBOutlet UITableView *commentTable;
//this is my mentions table that needs to be in ViewControllerA
@property (nonatomic, strong) UITableView *mentionTableView;
@end
视图控制器A.m
- (void)viewDidLoad
{
[super viewDidLoad];
**// i set up the mentionTable here**
self.mentionTableView.transform = transform;
self.mentionTableView.delegate = self;
self.mentionTableView.dataSource = self;
self.mentionTableView.tag = 1;
[self.view addSubview:self.mentionTableView];
**// i set up the commentTable here**
if (commentsController == nil) {
commentsController = [[justCommentsTable alloc] init];
}
[commentTable setDataSource:commentsController];
[commentTable setDelegate:commentsController];
[commentsController setHomeUserID:homeUserID];
[commentsController setGetEventHostIDforNotif:getEventHostIDforNotif];
[commentsController setGeteventIDfrSEgue:geteventIDfrSEgue];
[commentsController setGetEVENTNamefrSegue:getEVENTNamefrSegue];
**// i set commentsController to the Tableview in justCommentsTable class**
commentsController.view = commentsController.tableView;
}
只是CommentsTable.h
@interface justCommentsTable : UITableViewController<UITableViewDelegate, UITableViewDataSource,UITextFieldDelegate,UITextViewDelegate>
@end
justCommentsTable.m
@implementation justCommentsTable
//buttonTag is used for a button on the customCells
int buttonTag;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"commentCell";
customCell *cell =(customCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[customCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *commmentDict = [CommentArray objectAtIndex:indexPath.row];
NSString *commentText = [commmentDict objectForKey:@"comment"];
cell.textLabel.text = commentText;
// i need a custom button on the cells for other reasons
[cell.cellButton addTarget:self action:@selector(showButtonIndex:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
-(void)showButtonIndex:(UIButton*)button{
buttonTag = button.tag;
/*
buttonTag gets set here, and used in the prepareForSegue method
to find out what row the button was on.
*/
[self performSegueWithIdentifier:@"segueToViewControllerB" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"segueToViewControllerB"]){
//segue to profile from image button
ViewControllerB *VCB = segue.destinationViewController;
NSDictionary *commentDic = [CommentArray objectAtIndex:buttonTag];
/*
buttonTag was used to select the objectAtIndex
*/
NSString *commentTitle = [commentDic objectForKey:@"comment_title"];
VCB.title = commentTitle;
}
}
我知道我的问题在哪里,我只是不知道如何解决它。我已经搜索过像我这样的问题,但我找不到一个有可靠答案的问题。如果有人可以提供帮助,将不胜感激。谢谢!