2011-08-15 13 views
5

私はiOSの世界で初めてです。UITableViewはあなたのWiFi接続を設定しようとしたときのように見えて振る舞うカスタムセルを作る方法を知りたいデバイス。 (あなたはUITextFieldを含むセルを持つUITableViewを知っています.IPアドレスとそのすべてのものを設定する青いフォントで...)。各セルにテキストフィールドを持つ編集可能なUITableView

答えて

9

カスタムセルレイアウトを作成するには、少しのコーディングが必要になりますので、恐れてはいけません。

まず、新しい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にカスタムセルが追加されました。

幸運を祈る!

+3

ご協力ありがとうございます。実際には、私はコーディングを恐れていない、私はグラフィック要素を操作する上ではよくありません:) – Zak001

関連する問題