【问题标题】:How to create a table view programmatically?如何以编程方式创建表视图?
【发布时间】:2011-05-11 05:25:56
【问题描述】:

我需要在我的应用程序中使用 UITable View,它必须支持横向和纵向。

如果我直接从界面生成器中拖动 UItableview,那么我该如何准确控制它

如果不是,那么建议我以编程方式执行相同的操作。

谢谢 里兹万

【问题讨论】:

  • 尝试接受你之前的回答

标签: objective-c xcode ipad uitableview orientation


【解决方案1】:
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
        return 1;//Returns the no of sections in the tableview
    }

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        return 5;//Returns the no of rows in the tableview
    }

//This method is called everytime when a row is created.
    - (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];

        }

        // Configure the cell...
        cell.textLabel.text =@"tableview";

        return cell;

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-10-21
    相关资源
    最近更新 更多