菜鸟教程小白 发表于 2022-12-12 13:09:01

ios - tableview segue 到另一个 View Controller


                                            <p><p>我是编程新手,可能被一个简单的问题挂断了。我在我的表格 View 中为我的数组使用解析。选择该行后,我想转到另一个 ViewController 上的搜索栏。 segue 工作正常,tableview 工作正常,但我似乎无法让 objectId 通过。 </p>

<pre><code>#import &#34;bookmarkViewController.h&#34;
#import &#34;Parse/Parse.h&#34;
#import &lt;ParseUI/ParseUI.h&gt;
#import &#34;ViewController.h&#34;

@implementation bookmarkViewController

@synthesize postArray;


#pragma mark - View lifecycle

- (void)viewDidLoad
{
    ;

                   
initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self      
action:@selector(refreshButtonHandler:)]];

}

- (void)viewWillAppear:(BOOL)animated
{
    if ()
      ;
}

#pragma mark - Button handlers

- (void)refreshButtonHandler:(id)sender
{
    //Create query for all Post object by the current user
    PFQuery *postQuery = ;
    ];

    // Run the query
    [postQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
      if (!error) {
            //Save results and update the table
            postArray = objects;
            ;
      }
    }];
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:   
(NSInteger)section
{
    // Return the number of rows in the section.
    return postArray.count;
}

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

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

    // Configure the cell with the textContent of the Post as the cell&#39;s text label
    PFObject *post = ;
    ];

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath   
*)indexPath{
    NSLog(@&#34;cell tapped&#34;);
    PFObject *post = ;
    NSLog(@&#34;%@&#34;, post.objectId);
    ;



}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    ViewController *vc = ;

    vc.labelText = post.objectId;   
}
}


@end
</code></pre>

<p>在 vc.label.text 中,我总是使用未声明的标识符“post”,但我似乎不知道如何识别它。就是在上面的方法中。</p>

<p>NSLogs 正确回复 16:17:27.513 单元被点击
[应用] cgdVY7Eu9h</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>将您的 didSelectRowAtIndexPath 和 prepareForSegue 更改为:</p>

<pre><code>- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath* )indexPath{
    ;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{
    NSIndexPath *indexPath = ;

    NSLog(@&#34;cell tapped&#34;);
    PFObject *post = ;
    NSLog(@&#34;%@&#34;, post.objectId);
    ViewController *vc = ;

    vc.labelText = post.objectId;   
    }
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - tableview segue 到另一个 ViewController ,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/27238999/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/27238999/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - tableview segue 到另一个 View Controller