I need some help here so I will do my best to explain. I have worked on this all day and had no success (just learning!)
I have:
NSArray *getValue(NSString *iosearch)
{
mach_port_t masterPort;
CFTypeID propID = (CFTypeID) NULL;
unsigned int bufSize;
kern_return_t kr = IOMasterPort(MACH_PORT_NULL, &masterPort);
if (kr != noErr) return nil;
io_registry_entry_t entry = IORegistryGetRootEntry(masterPort);
if (entry == MACH_PORT_NULL) return nil;
CFTypeRef prop = IORegistryEntrySearchCFProperty(entry, kIODeviceTreePlane, (CFStringRef) iosearch, nil, kIORegistryIterateRecursively);
if (!prop) return nil;
propID = CFGetTypeID(prop);
if (!(propID == CFDataGetTypeID()))
{
mach_port_deallocate(mach_task_self(), masterPort);
return nil;
}
CFDataRef propData = (CFDataRef) prop;
if (!propData) return nil;
bufSize = CFDataGetLength(propData);
if (!bufSize) return nil;
NSString *p1 = [[[NSString alloc] initWithBytes:CFDataGetBytePtr(propData) length:bufSize encoding:1] autorelease];
mach_port_deallocate(mach_task_self(), masterPort);
return [p1 componentsSeparatedByString:@"\0"];
}
- (NSString *) serialnumber
{
NSArray *results = getValue(@"serial-number");
if (results) return [results objectAtIndex:0];
return nil;
}
- (NSString *) backlightlevel
{
NSArray *results = getValue(@"backlight-level");
if (results) return [results objectAtIndex:0];
return nil;
}
I have a tableView 开发者_JS百科set up and want to display my array in it so I then have:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {.............
.........................................................
cell.text = [results objectAtIndex:indexPath.row]; // error results undeclared here
return cell;
}
In my .h file I have:
@interface UIDevice_IOKitExtensionsViewController : UIViewController {
IBOutlet UITableView *tblSimpleTable;
NSArray *results;
}
@property (nonatomic, retain) NSArray *results;
- (NSString *) serialnumber;
- (NSString *) backlightlevel;
The problem is I get results undeclared as indicated above. I also can't figure how I could get serialnumber and backlightlevel to display on the click of a button or even at load. My attempts have thrown back errors like error: 'serialnumber' undeclared (first use in this function) and warnings like warning: 'return' with a value, in function returning void. Sorry for the long question!
Many thanks, Stuart
Did you retain the resutls in your two class level methods (serialnumber and backlightlevel)? For example, the serialnumber should be:
- (NSString *) serialnumber
{
NSArray *results = getValue(@"serial-number");
if (results) return [[results objectAtIndex:0] autorelease];
return nil;
}
Where are you declaring results
? It sure looks undeclared from the code you've posting. If you're using it as your data source, you should probably set it as an ivar. If you don't know what that means, this is a good place to start if you want to understand iPhone development.
精彩评论