我对iPhone开发相对较新,我试图添加uitableview来滚动视图,但它显示Sigabart错误,然后我以编程方式添加并添加了uitableviewdelegate和uitableview数据源给它,添加'noOfRowsInSection'方法的delgate方法不beeing called.c能够帮助我。在滚动视图中添加表视图
@interface Class : UIViewController<UITableViewDelegate,UITableViewDataSource> {
UITableView *table;
UIScrollView *scrView;
NSArray *array;
}
@property (nonatomic, retain) IBOutlet UIScrollView *scrView;
@end
here is my implementation
- (void)viewDidload
{
array = [[NSArray alloc]initWithObjects:@"harsha",@"theja",@"pandu", nil];
[super viewDidUnload];
table = [[UITableView alloc]initWithFrame:CGRectMake(0, 260, 360, 220)];
[self.view addSubview:table];
table.delegate = self ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
@end
我加入虽然Interface Builder中滚动视图,但我做的表格视图编程的,matically的TABL视图显示在屏幕上,但该方法不beeing称为
请向我们展示代码和委托方法:)您是否在interfacebuilder中建立了连接? 控制台用sigbart显示的错误是什么? – 2012-04-02 16:56:50
这有很多可能的原因,如果没有问题代码几乎不可能调试。 – mydogisbox 2012-04-02 17:01:31
在附注上,UITableView是UIScrollView的子类。所以如果你只需要标准的垂直滚动,就使用UITableView。 – cobbal 2012-04-03 10:54:53