Чтобы создать собственный макет ячейки, нужно немного кодировать, поэтому я надеюсь, что это вас не пугает.
Первое, что нужно создать - новый подкласс UITableViewCell
.Давайте назовем это InLineEditTableViewCell
.Ваш интерфейс InLineEditTableViewCell.h
может выглядеть примерно так:
#import <UIKit/UIKit.h>
@interface InLineEditTableViewCell : UITableViewCell
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UITextField *propertyTextField;
@end
А ваш InLineEditTableViewCell.m
может выглядеть так:
#import "InLineEditTableViewCell.h"
@implementation InLineEditTableViewCell
@synthesize titleLabel=_titleLabel;
@synthesize propertyTextField=_propertyTextField;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Here you layout your self.titleLabel and self.propertyTextField as you want them, like they are in the WiFi settings.
}
return self;
}
- (void)dealloc
{
[_titleLabel release], _titleLabel = nil;
[_propertyTextField release], _propertyTextField = nil;
[super dealloc];
}
@end
Следующее, что вы настраиваете UITableView
как обычно, по вашему мнению, контроллер.При этом необходимо реализовать метод протокола UITablesViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
.Прежде чем вставить свою реализацию для этого, не забудьте #import "InLineEditTableViewCell"
в вашем контроллере представления.После этого реализация выглядит следующим образом:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
InLineEditTableViewCell *cell = (InLineEditTableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"your-static-cell-identifier"];
if (!cell) {
cell = [[[InLineEditTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"your-static-cell-identifier"] autorelease];
}
// Setup your custom cell as your wish
cell.titleLabel.text = @"Your title text";
}
Вот и все!Теперь у вас есть пользовательские ячейки в UITableView
.
Удачи!