2012-01-15 12 views
1

私は、ModalViewの中にtableViewとTextFieldを追加しようとしています。私はそうする。私は、新しいビューコントローラを作成し、それをTable View ControllerとTextField Inside ModalView

#import <UIKit/UIKit.h> 


@protocol UYLModalViewControllerDelegate 

-(void) buttonDonePassed :(NSArray *) variables; 

@end 

@interface UYLModalViewController : UIViewController <UITableViewDelegate> 
{ 

    id<UYLModalViewControllerDelegate> delegate; 

    IBOutlet UITableView *tblView; 
    IBOutlet UITextField *textField; 

    NSMutableArray *cellsArray; 
    //UITextField *textField; 



} 
@property (nonatomic, assign) id<UYLModalViewControllerDelegate> delegate; 
@property (nonatomic, retain) IBOutlet UITableView *tblView; 
@property (retain, nonatomic) IBOutlet UITextField *textField; 


@end 

を与えるとの.mファイルに私は機能

#pragma mark - 
#pragma mark Table view data source 

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
    return 1; 
} 
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
    return [cellsArray count]; 
} 
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
    } 

    cell.textLabel.text = [cellsArray objectAtIndex:indexPath.row]; 
    // Configure the cell. 

    return cell; 
} 

とViewDidiLoad

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(buttonPassed:)]; 

    //UITableView *tableView = [[UITableView alloc] init]; 
    //[self] 
    cellsArray = [[NSMutableArray alloc] initWithObjects:@"one",@"two",@"three", nil]; 
    [tblView reloadData]; 
} 

を作成しかし、私のプログラムはTableViewDelegateに行っていませんメソッド(cellforrowAtIndexPathなど)

答えて

1

UYLModalViewControllerをに設定する必要がありますのdelegatedatasourceです。


それはあなたがInterface Builderを使用しているように見えるので、あなたがする必要があります。そして、HUDメニューからdatasourceを選択するのtableViewの

  1. control + clickFile's Owner
  2. に渡ってそれをドラッグします。
  3. 次にプロセスを繰り返したがdelegate

を選択注
はあなたのコントローラはまた、あなたを与えるUITableViewDatasourceに準拠する必要があります

@interface UYLModalViewController : UIViewController <UITableViewDelegate, UITableViewDatasource> 

1.

enter image description here

2.

enter image description here


ご希望の場合は、viewDidLoadたり、プログラム的にそれを行う場合は、tableViewを作成する任意の場所でのコードでこれを行うことができます。

self.tableView.delegate = self; 
self.tableView.datasource = self; 
+0

オイ、そうです=)ありがとうございます。あなたは私のXCodeにほとんど問題なく私を助けることができますか?スタンドアロンエディタとアシスタントエディタで同じファイルを編集すると、別のファイルが表示されます。しかし、ファイルの名前は同じです。そして、私はどのファイルがコンパイルされるのか理解できません(( – nabiullinas

+0

あなたはそれらが同じファイルであることを確かめていますか?)コンパニオンエディタはデフォルトで、あるウィンドウに '.h'ファイルを表示し、もう一つのウィンドウに' .m'を表示します。 –

+0

yes私はファイルの同じ名前を見るので、私は確信しています。例えば、私はprogectソリューションでファイルをクリックすると、その1つのバージョンを参照してください.nibファイルを編集し、アシスタントエディタを使用すると私は別のを参照してください( – nabiullinas

関連する問題