如何显示UILabel中方法的结果 [英] how to display results from a method in UILabel
问题描述
使用以下代码,我正在连接到Google API,当我单击按钮时,调用以下方法的结果将显示在标签字段上.
Using the following code I am connecting to Google API and when I click the button the result of the following method been called will display on label field.
我的问题是如何在标签字段中显示更多方法?
My question is how to display more methods in a label field?
例如,我想在标签"字段中显示一些4种方法或多个结果.
For example I want to display some 4 methods or multiple results in Label field.
在下面的代码中,我仅调用一种方法并仅显示一个结果.
In the code below I'm just calling one method and displaying only one result.
我想显示更多结果或多个结果,类似于Google搜索.
I want to display more results or multiple results something similar to Google search.
// .h file
{
IBOutlet UILabel* label;
NSMutableData *dataWebService;
}
@property (retain, nonatomic) NSMutableData *dataWebService;
-(IBAction)loadData;
// .m file
- (void)loadData
{
dataWebService = [[NSMutableData data] retain];
NSURLRequest *request = [[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://www.googleapis.com/customsearch/v1?key=AIzaSyDzl0Ozijg2C47iYfKgBWWkAbZE_wCJ-2U&cx=017576662512468239146:omuauf_lfve&q=lectures"]]retain];
[[NSURLConnection alloc]initWithRequest:request delegate:self];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[dataWebService setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[dataWebService appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(@"Error during connection: %@", [error description]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
self.dataWebService = nil;
// NSDictionary *dictionary = [responseString JSONValue];
NSDictionary *dictionaryReturn = (NSDictionary*) [[responseString JSONValue] objectForKey:@"context"];
[responseString release];
NSString *name = (NSString*) [dictionaryReturn objectForKey:@"title"];
label.text = [NSString stringWithFormat:@"lectures title: %@",name];
}
欢迎使用示例代码.
推荐答案
好吧,让我说清楚...您想在同一个UILabel中显示多个结果吗?如果是这样,则如果一次要显示多个结果,则最好使用UITextView或更佳的UITableView.UI标签是非常有限的.
Well, let me get this straight... You want to display multiple results within the same UILabel? If so, if you want to display more than one result at a time, you're best using a UITextView or better yet a UITableView. UI Labels are pretty limiting.
如果您想向UILabel添加更多行,则可以使用
If you want to add more lines to a UILabel though, you can use
textLabel.lineBreakMode = UILineBreakModeWordWrap;
textLabel.numberOfLines = 0;
我希望我能在正确的轨道上理解您的问题.
I hope I was on the right track understanding your question.
这篇关于如何显示UILabel中方法的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!