简单问题UITableView

时间:2010-11-02 02:26:51

标签: iphone objective-c

嘿嘿。我遇到了一个简单的事情。但我错过了一些细节。我正在尝试设置TableView的样式。我已经在视觉上编辑了表格,但似乎没有生效。

我做错了什么?

@implementation ComentariosViewController

@synthesize listaComentarios, tabelaComentarios;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [listaComentarios count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    //cell.font = [UIFont boldSystemFontOfSize:13];
}

NSString *cellValue = [listaComentarios objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;

return cell;
}

- (void)viewDidLoad
{
tabelaComentarios = [[UITableView alloc] initWithFrame:CGRectZero];

tabelaComentarios.delegate = self;
tabelaComentarios.dataSource = self;

//bkg.image = [UIImage imageNamed:@"BkgComentarios.png"];


tabelaComentarios.autoresizesSubviews = YES;
//
// Change the properties of the imageView and tableView (these could be set
// in interface builder instead).
//
tabelaComentarios.separatorStyle = UITableViewCellSeparatorStyleNone;
tabelaComentarios.rowHeight = 100;
tabelaComentarios.backgroundColor = [UIColor clearColor];
//imageView.image = [UIImage imageNamed:@"gradientBackground.png"];

//
// Create a header view. Wrap it in a container to allow us to position
// it better.
//
UIView *containerView =
[[[UIView alloc]
  initWithFrame:CGRectMake(0, 0, 300, 60)]
 autorelease];
UILabel *headerLabel =
[[[UILabel alloc]
  initWithFrame:CGRectMake(10, 20, 300, 40)]
 autorelease];
headerLabel.text = NSLocalizedString(@"Comentários", @"");
headerLabel.textColor = [UIColor grayColor];
headerLabel.font = [UIFont boldSystemFontOfSize:22];
headerLabel.backgroundColor = [UIColor clearColor];
[containerView addSubview:headerLabel];
self.tabelaComentarios.tableHeaderView = containerView;

self.view = tabelaComentarios;
}



-(void)loadView{


// XML

listaComentarios = [[NSMutableArray alloc] init];

TBXML * tbxml = [[TBXML tbxmlWithURL:[NSURL URLWithString:@"http://localhost/dev/mcomm/produto.xml"]] retain];
TBXMLElement * rootXMLElement = tbxml.rootXMLElement;

TBXMLElement * comentarios = [TBXML childElementNamed:@"comentarios" parentElement:rootXMLElement];

TBXMLElement * comentario = [TBXML childElementNamed:@"comentario" parentElement:comentarios];


while (comentario) {

    NSString * descText = [TBXML textForElement:comentario];
    NSLog(@"%@", descText);
    [listaComentarios addObject:descText];

    comentario = [TBXML nextSiblingNamed:@"comentario" searchFromElement:comentario];


}



[tbxml release];



}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {

[listaComentarios release];
[tabelaComentarios release];
[super dealloc];
}


@end

1 个答案:

答案 0 :(得分:0)

如果您使用“界面”构建器添加表格,请尝试注释掉这一行:

tabelaComentarios = [[UITableView alloc] initWithFrame:CGRectZero];