Ios 将NSMutableArray作为循环排入NSString?

Ios 将NSMutableArray作为循环排入NSString?,ios,objective-c,nsstring,nsmutablearray,Ios,Objective C,Nsstring,Nsmutablearray,如果有一个NSString,需要一个用户ID作为请求的URL: 一个人有一个NSMutableArray,他想一次一个地排队进入上面的调用?因此,基本上从NSMutableArray调用NSString 可以检查多个UITableView单元格,一旦完成,我就可以为推送的单元格行编制索引。这就是userIDArray现在的用途,我想用我从userIDArray得到的用户ID打个电话 for (NSDictionary* userIDDict in userIDArray) { us

如果有一个
NSString
,需要一个用户ID作为请求的URL:

一个人有一个
NSMutableArray
,他想一次一个地排队进入上面的调用?因此,基本上从
NSMutableArray
调用
NSString

可以检查多个UITableView单元格,一旦完成,我就可以为推送的单元格行编制索引。这就是userIDArray现在的用途,我想用我从userIDArray得到的用户ID打个电话

for (NSDictionary* userIDDict in userIDArray)
{   
    userIDArray = [[NSMutableArray alloc] init]; //I put this line in my viewdidload
    NSNumber* userID = [userIDDict objectForKey:@"UserID"];
}
UserIDArray是
NSMutableArray

这将是
NSMutableArray
中的
NSLog
,整数将是1、2和3

UserID: 1
UserID: 2
UserID: 3
因此,换句话说,我想从我的
NSMultiTableArray
1,2和3中获取结果,以便在
NSString
中使用:

NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=1"];

NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=2"];

NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=3"];
所以我会打第一个电话,等待结果,然后是第二个,最后是第三个

这能做到吗?我已经搜索了这个关于队列和这个,但我不确定这些是否是我需要的

UserDetailViewController.h文件:

@interface UserDetailViewController : UIViewController <UITableViewDelegate>{

long long expectedLength;
long long currentLength;
UITableView *userTableView;
NSIndexPath* checkedIndexPath;

}

@property (nonatomic, retain) NSArray *userIDJson;
@property (strong, nonatomic) NSDictionary *userIDDict;
@property (nonatomic, retain) NSIndexPath* checkedIndexPath;
@property (nonatomic, strong) NSMutableArray *userIDArray;
@property (nonatomic) NSInteger currentUserIndex;

@end
@interface UserDetailViewController:UIViewController{
长预期长度;
长电流长度;
UITableView*userTableView;
nsindepath*checkedIndexPath;
}
@属性(非原子,保留)NSArray*userIDJson;
@属性(强,非原子)NSDictionary*userIDDict;
@属性(非原子,保留)NSIndexPath*checkedIndexPath;
@属性(非原子,强)NSMutableArray*userIDArray;
@属性(非原子)NSInteger currentUserIndex;
@结束
UserDetailViewController.m文件:

@interface UserDetailViewController ()

@end

@implementation UserDetailViewController
@synthesize userIDJson;
@synthesize userIDDict;
@synthesize checkedIndexPath;
@synthesize userIDArray;
@synthesize currentUserIndex;

- (void)viewDidLoad
{
[super viewDidLoad];

userIDArray = [[NSMutableArray alloc] init];

[self.navigationController setNavigationBarHidden:NO];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//return self.loadedSearches.count;
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.userIDJson.count;
}

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CellIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;
}

cell.textLabel.text = self.userIDJson[indexPath.row][@"UserName"];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

if([self.checkedIndexPath isEqual:indexPath])
{
    cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
    cell.accessoryType = UITableViewCellAccessoryNone;
}

return cell;

}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
NSString *userStringIndex = [self.userIDJson objectAtIndex:indexPath.row];
if (thisCell.accessoryType == UITableViewCellAccessoryNone)
{
    thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
    [userIDArray addObject:userStringIndex];
}
else
{
    thisCell.accessoryType = UITableViewCellAccessoryNone;
    [userIDArray removeObject:userStringIndex];

}

}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {

if (self.currentUserIndex < userIDArray.count) {

NSNumber* userID = [[userIDArray objectForIndex:currentUserIndex]objectForKey:@"UserID"];

//Make the actual request here, and assign the delegate.
NSString *userProfile = [NSString stringWithFormat:@"http://example.com/userid=%@",userID];

self.currentUserIndex++;

NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:userProfile]];

NSString *userResult = [[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding];

NSURL *url = [[NSURL alloc] initWithString: userProfile];

NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];

userIDJson = [NSJSONSerialization JSONObjectWithData:dataURL 
                                            options:kNilOptions
                                              error:&error];
  }

 }

for (userIDDict in userIDArray)
{
    NSNumber* userID = [userIDDict objectForKey:@"UserID"];
    NSLog(@"%@", userID);
    NSArray* userName = [userIDDict objectForKey:@"UserName"]; 
}
@interface UserDetailViewController()
@结束
@UserDetailViewController的实现
@合成userIDJson;
@合成userIDDict;
@综合检查路径;
@综合用户阵列;
@综合当前用户索引;
-(无效)viewDidLoad
{
[超级视图下载];
userIDArray=[[NSMutableArray alloc]init];
[self.navigationController设置NavigationBarHidden:否];
}
-(NSInteger)表格视图中的节数:(UITableView*)表格视图
{
//返回self.loadedSearches.count;
返回1;
}
-(NSInteger)表视图:(UITableView*)表视图行数节:(NSInteger)节
{
返回self.userIDJson.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
静态NSString*CellIdentifier=@“CellIdentifier”;
UITableViewCell*单元格=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
如果(单元格==nil){
cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle重用标识符:CellIdentifier];
}
cell.textlab.text=self.userIDJson[indexath.row][@“UserName”];
cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
if([self.checkedIndexPath isEqual:indexPath])
{
cell.accessoryType=UITableViewCellAccessoryCheckmark;
}
其他的
{
cell.accessoryType=UITableViewCellAccessoryNone;
}
返回单元;
}
-(void)tableView:(UITableView*)tableView未选择RowatineXpath:(NSIndexPath*)indexPath
{
UITableViewCell*thisCell=[tableView cellForRowAtIndexPath:indexPath];
NSString*userStringIndex=[self.userIDJson objectAtIndex:indexath.row];
if(thisCell.accessoryType==UITableViewCellAccessoryNone)
{
thisCell.accessoryType=UITableViewCellAccessoryCheckmark;
[userIDArray addObject:userStringIndex];
}
其他的
{
thisCell.accessoryType=UITableViewCellAccessoryNone;
[userIDArray removeObject:userStringIndex];
}
}
-(无效)连接IDFinishLoading:(NSURLConnection*)连接{
if(self.currentUserIndex
NSURLConnection
可以通过构造函数获取委托
initWithRequest:delegate:
。因此,您需要使调用符合该协议的对象,我假设它是一个
UIViewController
。您可以使用委托中所需的方法之一触发下一个请求

例如,假设您具有指示当前索引的属性

@property (nonatomic) NSInteger currentUserIndex;
然后在将触发第一个请求的位置,为第一个用户进行呼叫。在某些委托方法中,例如

-(void)连接dFinishLoading:(NSURLConnection*)连接{
if(self.currentUserIndex

当然,如果您的连接调用不必是同步的,您可以用一种更简单的方法来完成。

调用
NSString
是什么意思?你的意思是你要用这个字符串作为一个URL,并用它建立一个互联网连接吗?是的,我已经设置了我的json内容,并用它建立了一个NSURL连接。我想从我的NSARRAY结果中打3个电话。那么,再从NSMultiTableArray中使用2和3进行另一次调用。但是我可能会在数组中收到3个以上的用户ID。我的数组是我从一个json结果中解析出来的结果
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    if (self.currentUserIndex < self.userIDArray.count) {
        NSNumber* userID = [[self.userIDArray objectAtIndex:self.currentUserIndex] objectForKey:@"UserID"];
        self.currentUserIndex++;
        //Make the actual request here, and assign the delegate.
    }
}