我是Objective-C的中介,我试图让此应用程序返回可以在本地创建的某种类型的UPnP设备网络。我使用的是UPnP Library,这是我的代码: 在viewDidLoad中,它使用建立的UPnP对象初始化数组mDevice。在表格视图单元中返回指定类型的UPnP设备的iOS应用程序
- (void)viewDidLoad
{
[super viewDidLoad];
UPnPDB* db = [[UPnPManager GetInstance] DB];
self.mDevices = [db rootDevices]; //BasicUPnPDevice
[db addObserver:(UPnPDBObserver*)self];
//Optional; set User Agent
//[[[UPnPManager GetInstance] SSDP] setUserAgentProduct:@"upnpxdemo/1.0" andOS:@"OSX"];
//Search for UPnP Devices
[[[UPnPManager GetInstance] SSDP] searchSSDP];
}
段的数量只是一个
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
在这里,我相信这是我的问题。我不能只返回我需要的设备类型。它返回所有创建的设备的行数,我只想返回指定设备的行数,女巫是BinaryLightDevice,我在下一个代码中从XML获取这些信息。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [mDevices count];
}
此代码用于自定义表格视图单元格的外观。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
BasicUPnPDevice *device = [self.mDevices objectAtIndex:indexPath.row];
[[cell textLabel] setText:[device friendlyName]];
if([[device urn] isEqualToString:@"urn:schemas-upnp org:device:lightswitch:1"])
{
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
我想单元格只返回光开关设备的名称,谢谢!
EDIT:
你好,我问了一个问题,但在这里困难的方式。我提到的是:如何将一行中存储的对象返回到先前创建的另一个对象?但是我想在声明表视图单元格之前这样做。 实施例:
BasicUPnPDevice *device = [self.mDevices objectAtIndex:indexPath.row];
这里*device
在行接收对象。我想创建另一个数组来存储过滤的设备,所以我可以通过这个新数组来设置行数,而不是由包含所有创建设备的数组。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [newArray count];
}