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

iphone - 如何共享数据计数(Coredata 中的关系)


                                            <p><p>我有一个问题...</p>

<p>我有几个(2) <code>ViewCotroller</code>。</p>

<p>名称分别为 <code>ViewController</code> 和 <code>DetailViewController</code></p>

<p><code>DetailViewController</code> 有数据(Coredata 中的关系)。</p>

<p>这是 <code>DetailViewController</code> 代码。</p>

<pre><code>NSSet *tags = self.bookInfo.details.tags;
tagNamesArray = [ initWithCapacity:tags.count];

for (Voca_Tag *tag in tags) {
    ;
}
</code></pre>

<p>我想在 <code>ViewController</code> 中使用那个 <code>tagNamesArray.count</code>。</p>

<p>还有,我被利用了</p>

<pre><code>DetailViewController *detailViewController = [init];

;
</code></pre>

<p>没用。</p>

<p>我想在 UITableView 上使用 Count 到 cell.text。</p>

<p>pastebin.com/RwuR6PDt << ViewController
pastebin.com/2F345vg7 << DetaulViewController </p>

<p>请检查...</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您应该编写您的委托(delegate):在 SecondViewController.H 中:</p>

<pre><code>@protocol messageDelegate &lt;NSObject&gt;
@optional
-(void) sendDataCount:(NSInteger) i;
@end
@interface SecondViewController : NSString
@property (nonatomic, assign) id &lt;messageDelegate&gt; delegate;
@end
</code></pre>

<p>在 SecondViewController.m 中:</p>

<pre><code>-(void)readyToSend
{
    ;

}
</code></pre>

<p>在 ViewController.h 中:</p>

<pre><code>@interface ViewController : UIViewController&lt;messageDelegate&gt;
@end
</code></pre>

<p>在 ViewController.m 中:在</p>

<pre><code>- (void)viewDidLoad {
SecondViewController *secondViewController = [ init];
secondViewController.delegate = self;
}
-(void) sendDataCount:(NSInteger) i
{
    NSLog(@&#34;Your Count=%d&#34;,i);
    //send Data using POST method
}
</code></pre>

<p>希望对您有所帮助!</p></p>
                                   
                                                <p style="font-size: 20px;">关于iphone - 如何共享数据计数(Coredata 中的关系),我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/17851832/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/17851832/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iphone - 如何共享数据计数(Coredata 中的关系)