Har*_*ami 4 iphone uitableview ios
我正在创建一个应用程序,我必须将一个单元格分为三个部分.例如,我必须在一个单元格中给出标题并在下面显示相应的数据.
我怎样才能做到这一点?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
{
static NSString *CellIdentifier = @"Cell";
myappAppDelegate *mydelegate=(myappAppDelegate *)[[UIApplication sharedApplication]delegate];
database *objdata =[mydelegate.myarray objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
if (indexPath.row == 0)
{
UILabel *temp = [[UILabel alloc] initWithFrame:CGRectMake(20, 0, 200, 44)];
temp.text =@"Main Balance";
temp.backgroundColor = [UIColor clearColor];
temp.font = [UIFont systemFontOfSize:19];
[cell addSubview:temp];
UILabel *temp1 = [[UILabel alloc] initWithFrame:CGRectMake(240, 0, 50, 44)];
temp1.text =@"2000";
temp1.backgroundColor = [UIColor clearColor];
temp1.font = [UIFont systemFontOfSize:19];
[cell addSubview:temp1];
else if(indexPath.row==1)
{
UILabel *temp = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 108, 44)];
temp.text =@"Income";
temp.backgroundColor = [UIColor clearColor];
temp.font = [UIFont systemFontOfSize:19];
[cell addSubview:temp];
}
else
{
UILabel *temp = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 108, 44)];
temp.text =[NSString stringWithFormat:@"%d",objdata.amount];
temp.backgroundColor = [UIColor clearColor];
temp.font = [UIFont systemFontOfSize:19];
[cell addSubview:temp];
}
enter code here
Run Code Online (Sandbox Code Playgroud)
在主屏幕上,我创建了One Main Blaance文本框和两个按钮,如收入,费用和一个最终显示按钮.当我点击收入它显示另一个视图,其中在TextBox中添加收入和一个按钮添加到主余额.我在该TextBox中键入收入金额然后单击保存,它将保存在数据库中我为费用做同样的事情然后我点击添加到主余额按钮,它将在主屏幕上显示的主余额文本框中添加或减去金额.然后点击主屏幕上的最终显示按钮,它将在TableView.I中显示三个标签收入,费用,主要余额......获取收入和费用下的值但它仅显示我在数据库中输入的初始值在设计时按查询.
我的问题: -假设我添加4个数据然后最终显示将显示所有数据即使我添加更多数据它也显示在最终显示....我希望你能得到我的观点..请指导我我很困惑.
使用此代码它将帮助您.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ShowMoreCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell = [self getCellContentView:CellIdentifier];
UILabel *lbl1 = (UILabel *)[cell viewWithTag:1];
[lbl1 setText:@"Label1"];
UILabel *lbl2 = (UILabel *)[cell viewWithTag:2];
[lbl2 setText:@"Label3"];
UILabel *lbl3 = (UILabel *)[cell viewWithTag:3];
[lbl3 setText:@"Label3"];
return cell;
}
- (UITableViewCell *)getCellContentView:(NSString *)cellIdentifier
{
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier] autorelease];
cell.backgroundColor=[UIColor clearColor];
CGRect lbl1Rect = CGRectMake(20, 5, 280, 30);
CGRect lbl2Rect = CGRectMake(20, 35, 280, 30);
CGRect lbl3Rect = CGRectMake(20, 70, 280, 30);
UILabel *lbl1 = [[UILabel alloc] initWithFrame:lbl1Rect];
lbl1.tag=1;
lbl1.font=[UIFont fontWithName:@"Helvetica" size:13];
lbl1.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lbl1];
[lbl1 release];
UILabel *lbl2 = [[UILabel alloc] initWithFrame:lbl2Rect];
lbl2.tag=1;
lbl2.font=[UIFont fontWithName:@"Helvetica" size:13];
lbl2.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lbl2];
[lbl2 release];
UILabel *lbl3 = [[UILabel alloc] initWithFrame:lbl3Rect];
lbl3.tag=1;
lbl3.font=[UIFont fontWithName:@"Helvetica" size:13];
lbl3.backgroundColor=[UIColor clearColor];
[cell.contentView addSubview:lbl3];
[lbl3 release];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2708 次 |
| 最近记录: |