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

前端 未结 2 1997
-上瘾入骨i
-上瘾入骨i 2021-01-19 14:03

Last week i have downloaded Xcode 4.2, so when i started building apps i\'ve tried to add an UITableView to one of my projects (as normal as i have been doing s

相关标签:
2条回答
  • 2021-01-19 14:30

    You should start with the project template "Master-Detail Application" and look at the mechanisms to create your own code in C++.

    But at the core, creating a UITableView is a two step:

    • init the view
    • plug it to its delegate/datasource

    also, this might help you: Can i write Cocoa Touch[iPhone] applications in C++ language

    0 讨论(0)
  • 2021-01-19 14:34

    in your .h file, add the following:

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

    right-click (or ctrl-click) and drag from your tableView to the File's Owner twice. Once, select "delegate", and once select "dataSource".

    Then, in your .m file, you need to implement the following:

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

    That should get you a working tableView.

    0 讨论(0)
提交回复
热议问题