Ios 如何在.m文件的两个方法中使用NSMutableArray?
我的.h文件中有:Ios 如何在.m文件的两个方法中使用NSMutableArray?,ios,objective-c,uitableview,nsmutablearray,global-variables,Ios,Objective C,Uitableview,Nsmutablearray,Global Variables,我的.h文件中有: #import <UIKit/UIKit.h> #import "SQLClient.h" @interface mgrViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, SQLClientDelegate>{ NSMutableArray *pajaros; } @property (weak, nonatomic) IB
#import <UIKit/UIKit.h>
#import "SQLClient.h"
@interface mgrViewController : UIViewController <UITableViewDelegate, UITableViewDataSource,
SQLClientDelegate>{
NSMutableArray *pajaros;
}
@property (weak, nonatomic) IBOutlet UITableView *miTabla;
@property (nonatomic, retain)NSMutableArray *pajaros;
@end
我在-voidviewDidLoad{}中向NSMutableArray pajaros添加了元素,我的问题是,如何在-UITableViewCell*tableView:UITableView*tableView cellForRowAtIndexPath:NSIndexPath*indexPath?中使用我的NSMutableArray pajaros
谢谢:
如果我对NSMutable数组使用count并打印该数字,则结果为1,因为我仅选择了一个数据,但仅当我使用:
...
[pajaros addObject:resulta];
}
NSInteger num = pajaros.count;
NSString *inStr = [NSString stringWithFormat: @"%ld", (long)num];
self.textView.text = inStr;
[client disconnect];
}];
...
但是如果我在.m文件show me 0的另一部分中执行该计数,我接下来的问题是为什么我的NSMutableArray只包含以下数据:
...
[pajaros addObject:resulta];
}
[client disconnect];
}];
...
?
谢谢你的帮助
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//这里是dequecell的代码
NSString*cellIdentifier=@cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell.textLabel.text = [pajaraos objectAtIndex:indexPath.row];
}
return cell;
}
您已经正确使用了阵列。有什么问题吗?请记住,异步加载阵列。加载数组后,应该在主线程上重新加载表视图。好的,谢谢,所以我想我将使用[self.miTabla reloadData];,但是我不知道我将在哪段代码中使用@rmaddy如何重新加载表?抱歉,我是Objective-C中的新手。@rmaddy我使用[self.miTabla reloadData];并且只显示其他数据,因为我为其他标签添加了其他数组此新数组不包含sql查询中的数据,是填充静态表单,但包含NSMutableArray pajaro的标签不显示任何内容。此代码不显示任何内容,但NSMutableArray pajaro包含唯一的数据,我在下一个代码中使用textView来查看[pajaros addObject:resulta];}之后的唯一数据代码:self.textView.text=[pajaros objectAtIndex:0];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell.textLabel.text = [pajaraos objectAtIndex:indexPath.row];
}
return cell;
}