IOS custom UITableView
According to different needs, you need to use the tableview structure, but each cell in it requires its own style, so I learned how to add the cell defined by myself to tableview.
First, you must create a class, inherit UITableViewCell, create an empty xib file, and set the class name in the class attribute. <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + pgltzybzcm9 "" alt = "\">
Code Section:
# Import "SettingViewController. h "# import" SettingViewCell. h "@ interface SettingViewController () @ end @ implementation SettingViewController @ synthesize listArray = _ listArray;-(id) initWithNibName :( NSString *) nibNameOrNil bundle :( NSBundle *) else {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view from its nib. NSArray * array = [NSArray arrayWithObjects: @ "room Settings", @ "Light Settings", @ "Curtain Settings", @ "scenario settings", @ "Air Conditioning Settings ", @ "Security Settings", @ "Network Settings", nil]; _ settingview. dataSource = self; // set the data source method _ settingview. delegate = self; // sets the proxy method self. listArray = array; // note that due to memory management problems, if not self. when listArray is assigned a value, _ listArray will be cleared and the program will crash}-(IBAction) backClicked :( id) sender {[self. navigationController popToRootViewControllerAnimated: YES];} // data source method-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section {return [_ listArray count];} // delegate method-(void) tableView :( UITableView *) tableView didSelectRowAtIndexPath :( NSIndexPath *) indexPath {switch (indexPath. row) {case 0: break; default: break; }}// Row display. implementers shocould * always * try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with outputs: // Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath {static NSString * cellIdentifier = @ "mycell "; settingViewCell * cell = (SettingViewCell *) [tableView topology: Topology]; if (cell = nil) {NSArray * array = [[NSBundle mainBundle] loadNibNamed: @ "SettingViewCell" owner: self options: nil]; cell = [array objectAtIndex: 0]; [cell setSelectionStyle: UITableViewCellSelectionStyleGray];} NSString * text = _ listArray [indexPath. row]; [[cell settingName] setText: text]; return cell;}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} -(void) dealloc {[_ back release]; [_ settingview release]; [super dealloc];} @ end