Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 在滚动视图中添加表视图_Objective C_Cocoa Touch - Fatal编程技术网

Objective c 在滚动视图中添加表视图

Objective c 在滚动视图中添加表视图,objective-c,cocoa-touch,Objective C,Cocoa Touch,我对iPhone开发相对较新,我尝试将uitableview添加到scroll view,但它显示了Sigabart错误,然后我通过编程添加了uitableviewdelegate和uitableview数据源,并将delegate设为self并添加“NoofrowsInstruction”方法delgate方法未被调用。有人能帮我吗 @interface Class : UIViewController<UITableViewDelegate,UITableViewDataSource&

我对iPhone开发相对较新,我尝试将uitableview添加到scroll view,但它显示了Sigabart错误,然后我通过编程添加了uitableviewdelegate和uitableview数据源,并将delegate设为self并添加“NoofrowsInstruction”方法delgate方法未被调用。有人能帮我吗

@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
@接口类:UIViewController{
UITableView*表;
UIScrollView*scrView;
NSArray*阵列;
}
@属性(非原子,保留)IBUISCROLLVIEW*scrView;
@结束
这是我的实现
-(无效)viewDidload
{
array=[[NSArray alloc]initWithObjects:@“harsha”,“theja”,“pandu”,nil];
[超级视频下载];
table=[[UITableView alloc]initWithFrame:CGRectMake(0,260,360,220)];
[self.view addSubview:table];
table.delegate=自我;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回[数组计数];
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“Cell”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault重用标识符:CellIdentifier]自动释放];
}
cell.textlab.text=[array objectAtIndex:indexath.row];
返回单元;
}
@结束

我正在通过Interface builder添加滚动视图,但我正在以编程方式执行表格视图。表格视图显示在屏幕上,但方法未被调用。您正在将代码放置在
视图卸载
方法中。将此代码移动到
viewDidLoad

- (void)viewDidUnload
{
    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 ;
}
应该是这样的:

- (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;
    table.dataSource = self;
}

您正在将代码放入
viewDidUnload
方法中。将此代码移动到
viewDidLoad

- (void)viewDidUnload
{
    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 ;
}
应该是这样的:

- (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;
    table.dataSource = self;
}

第一:您使用的是viewDidUnload而不是viewDidLoad

第二:添加
tableview.dataSource=self
并实现dataSource委托方法=)


您使用的是委托而不是数据源=)

1st:您使用的是viewDidUnload而不是viewDidLoad

第二:添加
tableview.dataSource=self
并实现dataSource委托方法=)


您使用的是委托而不是数据源=)

请向我们展示代码和委托方法:)您在interfacebuilder中建立了连接吗?您的控制台在sigbart中显示的错误是什么?有很多可能的原因,如果没有相关代码,几乎不可能进行调试。另一方面,UITableView是UIScrollView的子类。因此,如果您只需要标准的垂直滚动,只需使用UITableView。请向我们展示代码和委托方法:)您在interfacebuilder中建立了连接吗?您的控制台在sigbart中显示的错误是什么?有很多可能的原因,如果没有相关代码,几乎不可能进行调试。另一方面,UITableView是UIScrollView的子类。因此,如果您只需要标准的垂直滚动,只需使用UITableView。我在view中完成了这项工作,并按照您的要求加载了代码,在我的应用程序中,还有其他不同的内容要向您展示,我创建了一个类并将其粘贴到ViewDiDownload中。我真的很抱歉。非常感谢。[超级视频下载];已标记为折旧。我已在视图中完成。仅当您要求代码时才加载。在我的应用程序中,还有其他不同的内容要向您显示我已创建了一个类并将其粘贴到viewdidunload中。我非常抱歉。非常感谢。[超级视频下载];被标记为折旧。谢谢,我在视图中这样做了,只是加载了,但我没有将table.datasource添加到self。ading解决了它。有时它很简单=)很高兴我能帮忙。谢谢,我在视图中这样做了,只是加载了,但我没有将table.datasource添加到self。ading解决了它。有时它很简单=)很高兴我能帮上忙。