簡體   English   中英

如何在XOS 4.2上為IOS 5創建UITableView?

[英]How can i create an UITableView on Xcode 4.2,for IOS 5?

上周我已經下載了Xcode 4.2,所以當我開始構建應用程序時,我試圖將UITableView添加到我的一個項目中(正如我從開始開發以來一直在做的那樣),但是UITableView無法正常工作。 我正在尋找教程,但我沒有發現任何問題:我如何在Xcode 4.2上為IOS 5創建一個UITableView?

obs:我沒有使用storyBoard只是XIB的!

在.h文件中,添加以下內容:

@interface YourClass: UIViewController <**UITableViewDataSource, UITableViewDelegate**>

右鍵單擊(或按住Ctrl鍵單擊)並從tableView拖動到文件所有者兩次。 一次,選擇“委托”,然后選擇“dataSource”。

然后,在.m文件中,您需要實現以下內容:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 1;}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{return someNumber;}

- (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];
    }

    [[cell textLabel] setText:yourText];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //do what you want to with the information at indexPath.row
}

這應該會讓你找到一個工作表。

您應該從項目模板“Master-Detail Application”開始,並查看在C ++中創建自己的代碼的機制。

但在核心,創建UITableView是兩個步驟:

  • 初始化視圖
  • 將其插入其委托/數據源

此外,這可能對您有所幫助: 我可以用C ++語言編寫Cocoa Touch [iPhone]應用程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM