從tableview到另一個table view(使用Xcode 4.2和iOS 5)。Tableview跨越另一個tableview和自定義表格單元格不能顯示
FirstPage.h
#import "FavoritesController.h"
#import "Profiles.h"
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
FavoritesController * favoriteview = [[FavoritesController alloc] init];
[favoriteview setTitle:@"Favorites"];
NSMutableArray * profiles = [[NSMutableArray alloc]init ];
profiles = [NSMutableArray arrayWithCapacity:20];
Profiles * profile = [[Profiles alloc]init];
profile.profile_name = @"Woot";
profile.biz_type_desc = @"Woot 1";
profile.profile_address = @"123, woot";
profile.profile_email = @"[email protected]";
[profiles addObject:profile];
profile=[[Profiles alloc]init];
profile.profile_name = @"Jin-Aurora";
profile.biz_type_desc = @"Software";
profile.profile_address = @"682A";
profile.profile_email = @"[email protected]";
[profiles addObject:profile];
[self.navigationController pushViewController:favoriteview animated:YES];
favoriteview.profilelist = profiles;
}
FavoriesController.h
@interface FavoritesController : UITableViewController
@property(nonatomic,strong)NSMutableArray * profilelist;
@end
FavoriteController.m
#import "FavoritesController.h"
#import "Profiles.h"
#import "ProfileCell.h"
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.profilelist count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ProfileCell";
ProfileCell *cell = (ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
Profiles * profile = [self.profilelist objectAtIndex:indexPath.row];
cell.nameLabel.text = profile.profile_name;
cell.biztypeLabel.text = profile.biz_type_desc;
// Configure the cell...
return cell;
}
故事板表視圖
- Picture of prototype cell xib with Identity inspector
- Picture of prototype cell xib with Attributes inspector
這是我
2012-02-08 22錯誤:28:37.719測試[4668:F803]終止應用程序由於 未捕獲的異常「NSInternalInconsistencyException ',原因: 'UITableView dataSource必須從 返回一個單元格tableView:cellForRowAtIndexPath:'
嗨jmstone,我的代碼是這樣的。ProfileCell * cell =(ProfileCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if(cell == nil){cell = [[ProfileCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];} ( – 2012-02-09 01:48:20
如果你沒有得到任何單元格,在該方法中設置一個斷點,看它是否被擊中,否則,通常的罪魁禍首是你的數據源說該部分中沒有任何行(請參閱numberOfRowsInSection方法返回) – jmstone617 2012-02-09 02:28:51
嗨jmstone,它返回我tableViewCellStyleDefault由於我把initWithStyle,我設置cell.textLabel.text = profile.profile _名稱。它能夠顯示。但我想要顯示自定義表格單元:(我應該爲InitWithStyle放置自定義表格視圖單元格? – 2012-02-09 03:29:10