我已使用此代码自定义节标题的视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
supplierDetail = [sectionArray objectAtIndex:section];
NSArray *array = [[NSArray alloc] initWithArray:supplierDetail.leadDetails];
for(int i = 0 ; i<[array count]; i++){
dictionary = [[NSDictionary alloc] initWithDictionary:[array objectAtIndex:i]];
string = [dictionary valueForKey:@"mgrIDinfo"];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 60)];
view.backgroundColor = [UIColor colorWithRed:136.0/255.0 green:152.0/255.0 blue:163.0/255.0 alpha:1.0];
view.layer.masksToBounds = YES;
view.layer.borderColor = [UIColor colorWithRed:93.0/255.0 green:106.0/255.0 blue:114.0/255.0 alpha:1.0].CGColor;
view.layer.borderWidth = 0.5;
UILabel *label = [[[UILabel alloc] init] autorelease];
label.frame = CGRectMake(70, 10, 200, 25);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.shadowOffset = CGSizeMake(0.0, 1.0);
label.font = [UIFont boldSystemFontOfSize:16];
label.textAlignment = UITextAlignmentLeft;
UIImageView *imageView = [[UIImageView alloc] init];
imageView.frame = CGRectMake(10,3,40,40);
imageView.layer.cornerRadius = 6.0;
imageView.layer.masksToBounds = YES;
imageView.layer.borderColor = [UIColor blackColor].CGColor;
imageView.layer.borderWidth = 1.0;
label.text = [supplierDetail.systemname uppercaseString];;
[imageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",supplierDetail.logo]]];
[view autorelease];
[view addSubview:label];
[view addSubview:imageView];
if(string ){
NSLog(@"string in %@", string);
return view;
}
}
return 0;
}
}
但我想如果字符串存在,那么自定义视图标题将会出现,否则它将不会来.. 等待想法..