繁体   English   中英

简单问题UITableView

[英]Simple Question UITableView

大家好 我遇到了一件简单的事情。 但是我缺少一些细节。 我正在尝试设置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

如果您正在使用“界面”构建器添加表,请尝试注释掉以下行:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM