菜鸟教程小白 发表于 2022-12-13 17:24:13

iphone - 使用 Utility 模板的 Flipview 内的 Tableview


                                            <p><p>我是 iOS 开发新手,所以对于提出可能愚蠢的问题,我深表歉意。</p>

<p>我想做的是与默认天气应用程序非常相似的东西;如果应用程序有一个信息按钮,它会翻转到另一个 View ,该 View 有一个表格和一个完成按钮以返回应用程序。</p>

<p>我正在使用“实用程序”模板,它为我完成了大部分工作:)</p>

<p>但是,我现在正在努力将表格 View 添加到翻转 View 中。我在正确的道路上吗?我目前正在使用 Storyboard- 开始意识到这很可能是对 GUI 的限制(毕竟 GUI 只能走这么远)。如果是这样,这是否可能以编程方式进行,我将如何将其应用于默认的“实用程序应用程序”模板。</p>

<p>我使用的是 Xcode 4.2。</p>

<p>任何帮助将不胜感激。在此先感谢:)</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>首先,您需要将 UITableView 拖放到界面构建器中的 <code>flipsideViewController</code> 上。确保您喜欢 ViewController 的委托(delegate)和数据源。</p>

<p> <img src="/image/EWpVm.png" alt="enter image description here"/> </p>

<p>然后更改 <code>flipsideViewController.h</code> 为数组创建一个实例变量,该变量将存储单元格标签的文本,并使 Controller 符合表格委托(delegate)和数据源方法。</p >

<pre><code>@interface FlipsideViewController : UIViewController &lt;UITableViewDataSource, UITableViewDelegate&gt;
{
    NSArray *myArrayOfItems;
}
</code></pre>

<p>在 <code>flipsideViewController.m</code> alloc/init 中并在 <code>viewDidLoad</code></p> 中填充您的数组

<pre><code>myArrayOfItems = [ initWithObjects:@&#34;firstItem&#34;,@&#34;secondItem&#34;,@&#34;thirdItem&#34;,@&#34;fourthItem&#34;, nil];
</code></pre>

<p>最后,复制并粘贴以下内容,您应该有一个工作表!</p>

<pre><code>- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @&#34;Cell&#34;;
    UITableViewCell *cell = ;

    if (cell == nil) {
      cell = [ initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    cell.textLabel.text = ;

    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@&#34;Selected cell index:%i&#34;,indexPath.row);
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 使用 Utility 模板的 Flipview 内的 Tableview,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/13076495/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/13076495/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 使用 Utility 模板的 Flipview 内的 Tableview