use*_*025 3 iphone ios5 xcode4.3
我正在做一个简单的应用程序,它从json服务器查看项目
我在一个UIViewController中使用了UISegment来添加不同的子视图
- (IBAction)segmentSwitch:(id)sender {
UISegmentedControl *segmentedControl = (UISegmentedControl *) sender;
NSInteger selectedSegment = segmentedControl.selectedSegmentIndex;
if (selectedSegment == 0) {
instantiateViewControllerWithIdentifier:@"prestige"] animated:NO];
UIViewController *subController = [self.storyboard instantiateViewControllerWithIdentifier:@"prestige"];
[mainView addSubview:subController.view];
}
else if(selectedSegment == 1)
{
instantiateViewControllerWithIdentifier:@"latest"]];
//[self setView: [self.storyboard instantiateViewControllerWithIdentifier:@"latest"]];
//UIViewController *subController = [self.storyboard instantiateViewControllerWithIdentifier:@"latest"];
//[mainView addSubview:subController.view];
UITableViewController *tableVC =[self.storyboard instantiateViewControllerWithIdentifier:@"latest"];
[self.view addSubview:tableVC.tableView];
}
else if (selectedSegment == 2)
{
instantiateViewControllerWithIdentifier:@"contactUs"]];
UIViewController *subController = [self.storyboard instantiateViewControllerWithIdentifier:@"contactUs"];
[mainView addSubview:subController.view];
}
}
Run Code Online (Sandbox Code Playgroud)
当我选择Segment 2来查看uitableviewcontroller作为子视图x代码时,我的错误就出现了以下错误
exc_bad_access(代码= 1地址= 0x110ff210在线NSDictionary*latests = [latestArray objectAtIndex:indexPath.row];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"latestCell1";
latestCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSDictionary *latests = [latestArray objectAtIndex:indexPath.row];
NSString *latest_name_En = [latests objectForKey:@"title_en"];
NSString *logo1 = [latests objectForKey:@"logo"];
NSString *img1 = [latests objectForKey:@"img1"];
NSData *latestsImg1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:img1]];
NSData *latestsLogo1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:logo1]];
cell.latest_name_en1.text = latest_name_En;
dispatch_async(dispatch_get_main_queue(), ^{
cell.latest_img1.image = [UIImage imageWithData:latestsImg1];
cell.latest_logo1.image = [UIImage imageWithData:latestsLogo1];
});
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我确定UITableViewController工作正常,因为我试图单独运行它并且它也可以在没有自定义单元格的情况下尝试它并且它也可以工作但是使用custon cell作为子视图它会给出上面的错误.
use*_*025 14
谢谢您的帮助
我终于弄明白我用过了
[self addChildViewController:subController];
[mainView addSubview:subController.view];
Run Code Online (Sandbox Code Playgroud)
将tableview作为子视图添加到viewcontroller
它起作用了
| 归档时间: |
|
| 查看次数: |
3392 次 |
| 最近记录: |