这是我的问题我有一个表视图,其中包含3个三个标签(test1,test2,test3),它来自webservice。我想在单个表视图中加载所有三个标签。以下是我的代码:
for (NSDictionary *entry in entries) {
projectNames = [entries valueForKey:@"NM_PROJECT"];
taskNames = [entries valueForKey:@"TASk_NAME"];
subtaskNames = [entries valueForKey:@"SUBTASK_NAME"];
}
NSLog(@"project : %@", projectNames);
NSLog(@"taskNames : %@", taskNames);
NSLog(@"subtask : %@", subtaskNames);
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
// Return the number of sections.
return 1;
}
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [projectNames count];
}
-(UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identitifier = @"Cell";
DLPTSTableViewCell * cell = [tableView
dequeueReusableCellWithIdentifier:identitifier
forIndexPath:indexPath];
long row = [indexPath row];
cell.textLabel.text = projectNames[row];
cell.textLabel.text = taskNames[row];
cell.textLabel.text = subtaskNames[row];
return cell;
}
我想在projectnames数组中加载测试1,在tasknames数组中加载test 2,在子任务数组中加载test 3.
请帮帮我。
答案 0 :(得分:1)
如果要创建名为“DLPTSTableViewCell”的自定义UITableViewCell,则首先创建三个标签,即yourLabel1,yourLabel2,yourLabel3,并使用以下代码:
-(DLPTSTableViewCell *)getNewCell
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"DLPTSTableViewCell" owner:nil options:nil];
DLPTSTableViewCell *cell;
for (id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[DLPTSTableViewCell class]])
{
cell= (DLPTSTableViewCell *)currentObject;
return cell;
}
}
return nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CustomCell";
DLPTSTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [self getNewCell];
}
// for displaying values
cell.yourLabel1.text = your first value;
cell.yourLabel2.text = your second value;
cell.yourLabel3.text = your third value;
return cell;
}