Ios cellForRowAtIndexPath不';行不通
在我的xcode项目中,我有一个Ios cellForRowAtIndexPath不';行不通,ios,objective-c,uitableview,Ios,Objective C,Uitableview,在我的xcode项目中,我有一个视图和一个表视图。我还有一个“特殊”字符串,其中包含用于填充填充tableview的数组的对象。 例如: NSString *myValues=[[NSString alloc]init]; myValues = @"aaa$bbb$ccc?111$222$333?"; 如您所见,$和?把物体分开。 当我调用视图时,我用字符串填充数组,但tableview不起作用。下面是一些代码: 文件.H: #import <UIKit/UIKit.h> @i
视图
和一个表视图
。我还有一个“特殊”字符串,其中包含用于填充填充tableview的数组的对象。
例如:
NSString *myValues=[[NSString alloc]init];
myValues = @"aaa$bbb$ccc?111$222$333?";
如您所见,$和?把物体分开。
当我调用视图时,我用字符串填充数组,但tableview不起作用。下面是一些代码:
文件.H:
#import <UIKit/UIKit.h>
@interface EquipaggioVC : UIViewController <UITableViewDelegate, UITableViewDataSource>{
UITableView *tableViewEquipaggio;
UITableViewCell *nibLoadedCell;
NSMutableArray *arrayEquipaggio;
NSString *stringaDati;
}
@property (nonatomic, retain) IBOutlet UITableView *tableViewEquipaggio;
@property (nonatomic, retain) IBOutlet UITableViewCell *nibLoadedCell;
@property (nonatomic, retain) NSMutableArray *arrayEquipaggio;
@property (nonatomic, retain) NSString *stringaDati;
@end
#导入
@接口EquipaggioVC:UIViewController{
UITableView*tableViewEquipaggio;
UITableViewCell*nibLoadedCell;
NSMUTABLEARRY*arrayEquipaggio;
NSString*stringaDati;
}
@属性(非原子,保留)IBUITableView*tableViewEquipaggio;
@属性(非原子,保留)IBOutlet UITableViewCell*nibLoadedCell;
@属性(非原子,保留)NSMUTABLEARRY*arrayEquipaggio;
@属性(非原子,保留)NSString*stringaDati;
@结束
文件.M:
#import "EquipaggioVC.h"
#import "AppDelegate.h"
#import "ClassEquipaggio.h"
@interface EquipaggioVC ()
@end
@implementation EquipaggioVC
@synthesize tableViewEquipaggio;
@synthesize nibLoadedCell;
@synthesize arrayEquipaggio;
@synthesize stringaDati;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
-(NSString *)uuid
{
//to create an ID
CFUUIDRef uuidRef = CFUUIDCreate(NULL);
CFStringRef uuidStringRef = CFUUIDCreateString(NULL, uuidRef);
CFRelease(uuidRef);
return [(NSString *)uuidStringRef autorelease];
}
-(void)loadTestData:(NSString*)stringaDatiArray{
//populate the array by the string.
if(stringaDatiArray!=nil){
NSArray *elenco=[stringaDatiArray componentsSeparatedByString:@"?"];
for (int i=0; i<([elenco count]-1) ; i++) {
NSString *dettagliEquipaggio=[[NSString alloc]init];
dettagliEquipaggio=[elenco objectAtIndex:i];
NSArray *dettagli=[dettagliEquipaggio componentsSeparatedByString:@"$"];
ClassEquipaggio *aEquipaggio=[[ClassEquipaggio alloc]init];
aEquipaggio.idMembro=[dettagli objectAtIndex:0];
aEquipaggio.sessoMembro=[dettagli objectAtIndex:1];
aEquipaggio.dataNascitaMembro=[dettagli objectAtIndex:2];
[arrayEquipaggio addObject:aEquipaggio];
[aEquipaggio release];
}
}
}
- (UITableViewCell *)tableView:(UITableView *)tableEquipaggioView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
static NSString *sLoadNibNamed;
UITableViewCell *cell;
ClassEquipaggio *aEquipaggio=[arrayEquipaggio objectAtIndex:indexPath.row];
cell = [tableEquipaggioView dequeueReusableCellWithIdentifier:CellIdentifier];
sLoadNibNamed=@"EquipaggioCell";
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:sLoadNibNamed owner:self options:NULL];
cell = [self typeNibLoadCell:aEquipaggio.idMembro];
}
// Configure the cell
UILabel *tipoSessoLabel = (UILabel*) [cell viewWithTag:1];
tipoSessoLabel.text = aEquipaggio.sessoMembro;
UILabel *dataNascitaLabel=(UILabel*)[cell viewWithTag:2];
dataNascitaLabel.text=aEquipaggio.dataNascitaMembro;
return cell;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
return [arrayEquipaggio count];
}
-(UITableViewCell *)typeNibLoadCell:(NSString *)named{
return nibLoadedCell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return NO;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (void)viewDidLoad
{
[super viewDidLoad];
arrayEquipaggio=[[NSMutableArray alloc]init];
stringaDati=[[NSString alloc]init];
tableViewEquipaggio=[[UITableView alloc]init];
}
-(void)viewDidAppear:(BOOL)animated{
AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
UIBarButtonItem * btnIndietroa = [[[UIBarButtonItem alloc] initWithTitle:@"Indietro"
style:UIBarButtonItemStyleBordered
target:self
action:@selector(editNavButtonPressed)]autorelease];
[self.navigationItem setLeftBarButtonItem:btnIndietroa];
stringaDati = [[NSUserDefaults standardUserDefaults] objectForKey:@"stringaDati"];
if(stringaDati!=nil){
[arrayEquipaggio removeAllObjects];
[self loadTestData:stringaDati];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc{
[super dealloc];
}
@end
#导入“EquipaggioVC.h”
#导入“AppDelegate.h”
#导入“ClassEquipaggio.h”
@接口EquipaggioVC()
@结束
@实现方法
@综合tableViewEquipaggio;
@合成负载型细胞;
@合成arrayEquipaggio;
@合成斯特林加蒂;
-(id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
{
self=[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
如果(自我){
//自定义初始化
}
回归自我;
}
-(NSString*)uuid
{
//创建一个ID
CFUUIDRef uuidRef=cfuuiddcreate(空);
CFStringRef uuidStringRef=CFUUIDCreateString(NULL,uuidRef);
CFRelease(uuidRef);
返回[(NSString*)uuidStringRef autorelease];
}
-(void)loadTestData:(NSString*)stringaDatiArray{
//按字符串填充数组。
if(stringaDatiArray!=nil){
NSArray*elenco=[stringaDatiArray组件由字符串分隔:@“?”];
对于(int i=0;i从您的问题来看,您的问题是没有调用方法cellforrowatinexpath
,正如您所说的[arrayEquipaggio count]
返回0
由于您在返回值为0
的方法numberOfRowsInSection
中使用该数组,因此表没有调用方法cellforrowatinexpath
。因为您告诉表没有行
如果希望填充表,请检查数组返回的值是否大于0
简而言之,它没有数据来填充您的表,这就是它无法工作的原因
检查是否在视图中显示:(BOOL)动画您正在将任何内容拉入stringaDati
NSLog(@"info: %@",stringaDati);
请检查[arrayEquipaggio count]
的值,我指的是行数。两个问题:您是否尝试过这样定义字符串>。我想您错过了@“”定义它。第二个:numberOfRowsInSection返回多少?你说的不工作是什么意思?“它不工作”是什么意思?tableView没有调用它的数据源方法,或者数组可能是空的吗?@Marspace字符串是正确的,我的错现在我编辑了这个问题;)