【问题标题】:How do I call a method from another method of the same NSObject?如何从同一个 NSObject 的另一个方法调用一个方法?
【发布时间】:2011-08-31 21:05:37
【问题描述】:

我的 NSObject 中有两个方法。

我想知道如何在一种方法中从另一种方法中设置文本,然后从我设置文本的方法中执行该方法?

这是我到目前为止所做的......只是在尝试在视图之间传递东西和设置表格视图时迷失了方向。

- (IBAction) getManufacturers
{
    //set manufacture.php
    NSString *manufactureString = [[NSString alloc] initWithString:@"manufacture.php"];
    submissionString = manufactureString;
    self.grabURLInBackground; //<--- this is wrong, how do I call my other method?
}

//...


- (IBAction)grabURLInBackground:(id)sender
{
    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8888/CodeTest/%@", settexthere];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request startAsynchronous];
}

//已更新: 所以我最终做的只是将一个 NSString 参数添加到从我的其他方法设置的grabURLInBackground 方法中,如下所述

[self grabURLInBackground:submissionString];

一切都好。

现在我只需要弄清楚如何将输入的数据传递给新的 uitableview.. :) 谢谢你们的帮助。

【问题讨论】:

  • 您的制造字符串正在泄漏,应该释放。或者更好的是,只需执行 submitString = @manufacture.php"。由于 submitString 可能是保留属性,请改用 self.submissionString = @manufacture.php"。

标签: iphone ios asihttprequest


【解决方案1】:
[self grabURLInBackground:nil];

如果你在原型中声明了函数,这应该可以工作

我想你想设置字符串?在这种情况下,您需要一个新功能

原型

- (void) grabURLInBackgroundWithSubmission:(NSString*):submission;

实施

- (void) grabURLInBackgroundWithSubmission:(NSString*):submission{
    NSURL *url = [NSURL URLWithString:@"http://127.0.0.1:8888/instaCodeTest/%@", submission];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request startAsynchronous];
}

并调用它 [self grabURLInBackgroundWithSubmission:submissionString];

【讨论】:

  • 如果我将 id 设置为字符串会发生什么,因为该函数来自 ASIHttpRequest 变形器。我正在考虑更改,但我不确定它是否会弄乱函数。
  • 其实不回答这个问题。我只是想用 NSStrin 做我自己的方法 *...谢谢你的回答。
  • 获取从其他地方调用的函数,比如在 Interfacebuilder 中?如果没有,你可以覆盖它
【解决方案2】:

像这样?

[self grabURLInBackground:nil]

但您可能希望将功能从 grabURLInBackground 移到另一个方法,这样您就不必传递一个虚拟的 nil 参数。

【讨论】:

    猜你喜欢
    • 2015-06-16
    • 1970-01-01
    • 1970-01-01
    • 2011-01-14
    • 2010-12-24
    • 2013-10-08
    • 1970-01-01
    • 2014-11-07
    相关资源
    最近更新 更多