Iphone 将数组插入tableview
向表视图插入数组时遇到问题。我有一个数组,并将其存储在Iphone 将数组插入tableview,iphone,objective-c,ios,uitableview,xcode4.3,Iphone,Objective C,Ios,Uitableview,Xcode4.3,向表视图插入数组时遇到问题。我有一个数组,并将其存储在alDescArray中 这是alDescArray=( “区块1”, “区块2”, “区块3” )通过NSLog打印的位置。表中没有显示任何错误代码的哪一部分 - (void)viewDidLoad { NSArray *BusRoute = alightDesc; int i; int count = [BusRoute count]; for (i = 0; i < count; i++)
alDescArray
中
这是alDescArray=(
“区块1”,
“区块2”,
“区块3”
)
通过NSLog打印的位置。表中没有显示任何错误代码的哪一部分
- (void)viewDidLoad
{
NSArray *BusRoute = alightDesc;
int i;
int count = [BusRoute count];
for (i = 0; i < count; i++)
{
NSDictionary *dic = [BusRoute objectAtIndex: i];
NSDictionary *STEPS = [dic valueForKey:@"STEPS"];
alDescArray = [STEPS valueForKey:@"AlightDesc"];
}
[super viewDidLoad];
}
请帮助,谢谢显然您的tableview的委托/数据源未设置 h
YourClassName:ParentClass
m
-(void)viewDidLoad
{
yourTableView.delegate=self;
yourTableView.dataSource=self;
NSArray*BusRoute=下车描述;
int i;
int count=[总线路由计数];
对于(i=0;i
是否设置了tableView的委托?需要保留数组对象alDescArray。像alDescArray=[[STEPS valueForKey:@“AlightDesc”]retain][alDescArray objectAtIndex:indexPath.row]
->数组中的元素是NSString
?还有一件事,您需要检查您的表是否为数据源注册。YourHeader:ParentClass
然后self.tableView.delegate=self代码>好的,谢谢。但是我按照你说的做了,它在以下位置出现了另一个问题:-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{return[alDescArray count];}
其中返回[alDescArray count]
获取了一个错误EXC_BAD_ACCESS(code=1,address=0xc07e5e7b
是因为这个数组吗?alDescArray=(“Block1”、“Block2”、“Block3”)
您是如何声明alDescArray
*alightDesc;
和@属性(保留,非原子的)NSArray*alDescArray;
ok solve Thank不应使用@属性(保留,非原子)NSArray*alDescArray;
应使用alDescArray=[[STEPS valueForKey:@“AlightDesc”]保留]
@kapil Ghai
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [alDescArray 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 = [alDescArray objectAtIndex:indexPath.row];
return cell;
}
YourClassName : ParentClass <UITableViewDelegate, UITableViewDataSource>
- (void)viewDidLoad
{
yourTableView.delegate = self;
yourTableView.dataSource = self;
NSArray *BusRoute = alightDesc;
int i;
int count = [BusRoute count];
for (i = 0; i < count; i++)
{
NSDictionary *dic = [BusRoute objectAtIndex: i];
NSDictionary *STEPS = [dic valueForKey:@"STEPS"];
alDescArray = [STEPS valueForKey:@"AlightDesc"];
}
[super viewDidLoad];
}