我在UITable單元格上做了一個空項目並且它工作正常。使用相同的代碼,我將其添加到有多個xib鏈接的現有項目中。從另一個xib導航到此頁面時,表格單元格確實出現,但內容和所需的單元格數量未運行。當從另一個XIB導航時,UITable單元格不在XIB上顯示
下面是我的當前項目的代碼:
OptionViewController.m:
#import "OptionViewController.h"
#import "FishAppDelegate.h"
#import "MainViewController.h"
#import "PetFishViewController.h"
#import "MarineFishViewController.h"
@interface OptionViewController()
@end
@implementation OptionViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title [email protected]"Choose a category :)";
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(IBAction)PetFish:(id)sender
{
PetFishViewController *petFish = [[PetFishViewController alloc]initWithNibName:nil bundle:nil];
[[self navigationController] pushViewController:petFish animated:YES];
}
// this is the sub class containing table cells
-(IBAction)MarineFish:(id)sender
{
MarineFishViewController *MarineFish = [[MarineFishViewController alloc]initWithNibName:nil bundle:nil];
[[self navigationController] pushViewController:MarineFish animated:YES];
}
@end
在當前子類:海洋魚類
MarineFishController.h
#import <Foundation/Foundation.h>
@interface MarineFishViewController : UITableViewController
{
NSMutableArray *fishList;
}
@end
MarineFishController.m:
#import "MarineFishViewController.h"
#import "MarineFish.h"
@implementation MarineFishViewController
{
/*NSArray *tableData;
NSArray *thumbnail;
*/
}
-(id) init{
//call the superclass
self = [super initWithStyle:UITableViewStyleGrouped];
if(self){
fishList = [[NSMutableArray alloc] init];
MarineFish *Item1 = [[MarineFish alloc] initWithName:@"Shark" imageName:@"Sea.jpg"];
[fishList addObject:Item1];
}
return self;
}
-(id)initWithStyle:(UITableViewStyle)style{
return [self init];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [fishList count];
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//create an instance of uitableviewcell
//check for a reusable cell first, use if exist
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"];
//if there is no reusable cell of this type,create new one
if(!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"UITableViewCell"];
}
//set text on the cell
MarineFish *p = [fishList objectAtIndex:[indexPath row]];
[[cell textLabel] setText:[[NSString alloc] initWithFormat:@"%@",[p fishName]]];
}
@end
關於表。我只在魚列表中添加了一個item1,因此應該只顯示一個單元格。
你說你從另一個項目中帶入了代碼?您是否將相關的.m文件添加到新目標中? – 2013-03-12 01:33:43
上傳項目並共享鏈接 – 2013-03-12 02:28:20
http://www.mediafire.com/?teq0bc6c37ip2nn 這是該項目的鏈接,附有兩張圖片供參考。請幫忙,謝謝! – 2013fyp 2013-03-12 02:55:06