Iphone 获取UITableView节和行后。。。这个代码是做什么的?

Iphone 获取UITableView节和行后。。。这个代码是做什么的?,iphone,ios,cocoa-touch,uitableview,uiview,Iphone,Ios,Cocoa Touch,Uitableview,Uiview,有谁能解释一下在拿到NSArray后这个代码做了什么 - (UIViewController *)sampleForIndexPath:(NSIndexPath *)indexPath { NSArray *samples = [samples_ objectAtIndex:indexPath.section]; Class clazz = [samples objectAtIndex:indexPath.row]; UIViewController *instance

有谁能解释一下在拿到NSArray后这个代码做了什么

- (UIViewController *)sampleForIndexPath:(NSIndexPath *)indexPath {

    NSArray *samples = [samples_ objectAtIndex:indexPath.section];
    Class clazz = [samples objectAtIndex:indexPath.row];
    UIViewController *instance = [[clazz alloc] initWithNibName:nil bundle:nil];
    return [instance autorelease];
  }

我得到了一份。。。那么我们如何将行的值分配给类呢???

获取数组后,它使用以下方法检索特定的

Class clazz=[samples-objectAtIndex:indexath.row]

然后它使用类实例化一个
UIViewController
对象,并返回该对象:

UIViewController *instance = [[clazz alloc] initWithNibName:nil bundle:nil];
return [instance autorelease];

获取数组后,它使用以下方法检索特定的

Class clazz=[samples-objectAtIndex:indexath.row]

然后它使用类实例化一个
UIViewController
对象,并返回该对象:

UIViewController *instance = [[clazz alloc] initWithNibName:nil bundle:nil];
return [instance autorelease];

这里的数组样本包含类型的对象。您可以直接使用类名或使用类对象/变量创建类的实例。比如说,

/* One Way */

// Create an instance of MyViewController deirectly
UIViewController *vc = [[MyViewController alloc] init];

/* Another Way */

// The following line returns a class object
Class cls = NSClassFromString(@"MyViewController");
// The below is just for an example. This also returns a class object 
Class cls = [MyViewController class]; 
// Create an instance of MyViewController from the class object
UIViewController *vc = [[cls alloc] init];

您的代码使用第二种方法从[samples objectAtIndex:indexPath.row]返回的类对象分配视图控制器对象。

这里数组samples包含类型的对象。您可以直接使用类名或使用类对象/变量创建类的实例。比如说,

/* One Way */

// Create an instance of MyViewController deirectly
UIViewController *vc = [[MyViewController alloc] init];

/* Another Way */

// The following line returns a class object
Class cls = NSClassFromString(@"MyViewController");
// The below is just for an example. This also returns a class object 
Class cls = [MyViewController class]; 
// Create an instance of MyViewController from the class object
UIViewController *vc = [[cls alloc] init];
代码使用第二种方法从[samples objectAtIndex:indexPath.row]返回的类对象分配视图控制器对象