- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
NSLog(@"Returning num sections");
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSLog(@"Returning num rows");
return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"Trying to return cell");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell =[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] ;
}
cell.textLabel.text = @"Hello";
NSLog(@"Returning cell");
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Selected row");
}
- (void)viewDidLoad
{
[super viewDidLoad];
m_titleTable = [[UITableView alloc] init] ;
m_titleTable.dataSource = self;
m_titleTable.delegate = self;
m_titleTable.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:m_titleTable];
// Do any additional setup after loading the view from its nib.
}
-(void)titleAction:(id)sender{
NSLog(@"Calling");
UIViewController* popoverContent = [[UIViewController alloc]
init];
TitleViewController *popoverView = [[TitleViewController alloc]initWithNibName:@"TitleViewController" bundle:nil];
popoverContent.view = popoverView.view;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(150, 150);
//create a popover controller
self->popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self->popoverController presentPopoverFromRect:btn_title.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}tableview崩溃错误消息
[__NSCFType tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x6e7dca0
2012-08-28 14:17:10.539 Demo[2790:f803] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType tableView:cellForRowAtIndexPath:]: unrecognized selector sent to instance 0x6e7dca0'发布于 2012-08-28 17:04:46
你的问题是你的视图控制器正在被释放。你不应该这样做:
UIViewController* popoverContent = [[UIViewController alloc]
init];
TitleViewController *popoverView = [[TitleViewController alloc]initWithNibName:@"TitleViewController" bundle:nil];
popoverContent.view = popoverView.view;假设你使用的是ARC,你的popoverView对象将被释放。这也是不正确的。您几乎不应该实例化UIViewController,也绝对不应该将一个视图控制器的view实例分配给另一个视图控制器!
下面是我重写titleAction:方法的方法:
TitleViewController *titleViewController = [[TitleViewController alloc]initWithNibName:@"TitleViewController" bundle:nil];
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover = CGSizeMake(150, 150);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:titleViewController];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:btn_title.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];至少,UIPopoverController应该保持对titleViewController的强引用,并防止它被释放。
PS我把你的"self -> popoverController“改成了self.popoverController,因为->对于你想做的事情并不是真的正确。点表示法明确表示您正在设置对象的属性。
发布于 2012-08-28 17:11:02
在viewDidLoad中,您可以分配和初始化一个UITableView,并将其连接到自身。您没有定义UITableView?并在nib中进行连接?在没有看到整个项目的情况下,我猜测你有UITableViews -这是一个问题,但不一定是崩溃问题。你继承了UITableViewController作为基类吗?
https://stackoverflow.com/questions/12155722
复制相似问题