由于某些原因,我必须从UITableView中提取单元格的文本或值。我有以下表格方法:
- (void)loadCollection_Information
{
_collection_InformationCellData = [[NSMutableArray alloc] init];
NSMutableArray *cells_1 = [[NSMutableArray alloc] init];
NSDictionary *cellContainer_1_1 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Brett Whiteley", @"Author", @"", @"", @"", @"", nil] forKeys:[NSArray arrayWithObjects:@"Text", @"Detail Text", @"Image", @"Text Color", @"Detail Text Color", @"Accessory", nil]];
[cells_1 addObject:cellContainer_1_1];
NSDictionary *cellContainer_1_2 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"1976", @"Year", @"", @"", @"", @"", nil]
forKeys:[NSArray arrayWithObjects:@"Text", @"Detail Text", @"Image", @"Text Color", @"Detail Text Color", @"Accessory", nil]];
[cells_1 addObject:cellContainer_1_2];
NSDictionary *cellContainer_1_3 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Canvas, Oil", @"Materials", @"", @"", @"", @"", nil] forKeys:[NSArray arrayWithObjects:@"Text", @"Detail Text", @"Image", @"Text Color", @"Detail Text Color", @"Accessory", nil]];
[cells_1 addObject:cellContainer_1_3];
NSDictionary *cellContainer_1_4 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Social Comment & Hard Edged Abstraction", @"Style", @"", @"", @"", @"", nil]
forKeys:[NSArray arrayWithObjects:@"Text", @"Detail Text", @"Image", @"Text Color", @"Detail Text Color", @"Accessory", nil]];
[cells_1 addObject:cellContainer_1_4];
NSDictionary *cellContainer_1_5 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"182.0 high * 200.0 wide cm", @"Size", @"", @"", @"", @"", nil]
forKeys:[NSArray arrayWithObjects:@"Text", @"Detail Text", @"Image", @"Text Color", @"Detail Text Color", @"Accessory", nil]];
[cells_1 addObject:cellContainer_1_5];
NSDictionary *sectionContainer_1 = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:@"Collection Information", cells_1, @"", nil]
forKeys:[NSArray arrayWithObjects:@"Title", @"Cells", @"Footer Title", nil]];
[_collection_InformationCellData addObject:sectionContainer_1];
_collection_InformationSelectedRow = 0;
_collection_InformationSelectedSection = 0;
_collection_InformationShowHeader = YES;
[_collection_Information setEditing:NO];
[_collection_Information reloadData];
}
和didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (tableView == _collection_Information) {
if (indexPath.section == 0 && indexPath.row == 0) {
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Brett_WhiteleyViewController"];
[self.navigationController pushViewController:controller animated:YES];
}
if (indexPath.section == 0 && indexPath.row == 1) {
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Year_1960s_70sViewController"];
[self.navigationController pushViewController:controller animated:YES];
}
if (indexPath.section == 0 && indexPath.row == 2) {
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"Canvas_and_OilViewController"];
[self.navigationController pushViewController:controller animated:YES];
}
if (indexPath.section == 0 && indexPath.row == 3) {
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"SC_and_HE_AbstractionViewController"];
[self.navigationController pushViewController:controller animated:YES];
}
}
//Get the Dictionary Object at index 0, to check out the object.
NSLog(@"%@",[_collection_InformationCellData objectAtIndex:0]);
//Store the Objects from dictionary in temp Array.
NSArray *temp = [[_collection_InformationCellData objectAtIndex:indexPath.section] valueForKey:@"Cells"];
//Get the object based on Row Selection in UITableView.
NSLog(@"%@",[[temp objectAtIndex: indexPath.row] valueForKey:@"Text"]);
}
我需要提取NSStrings,例如:Brett Whiteley,1976,Canvas,Oil,Social Comment&硬边抽象分开,并在另一种方法中将其放入以下代码中:
-(NSString *)maxmsg
{
NSString *msg;
int maxint=-1;
RecommendationData *obj = [RecommendationData getInstance];
if(obj.author<=5 && obj.year<=5 && obj.material<=5 && obj.style<=5)
{
msg=@"nothing";
}
else if( obj.author >= obj.year && obj.author >= obj.material && obj.author >= obj.style)
{
maxint=obj.author;
//the code for placing the value
obj.maxValue= (place value here);
msg=@"It seems that you are interested in the author of this collection.";
}
else if(obj.year >= obj.author && obj.year >= obj.material && obj.year >= obj.style)
{
maxint=obj.year;
//the code for placing the value
obj.maxValue= (place value here);
msg=@"It seems that you are interested in this period of the collection.";
}
else
{
msg=@"equal";
}
return msg;
}
谁能告诉我怎么做?
答案 0 :(得分:0)
从另一种方法接收“Brett Whiteley”,你可以致电
_collection_InformationCellData[ CellContainerIndex ][ @"Cells" ][ 0 ][ "Text" ]
但你需要保存某个/知道正确的CellContainerIndex。可能你的情况只是0?
答案 1 :(得分:0)
以下是执行此操作的方法:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//Get the Dictionary Object at index 0, to check out the object.
NSLog(@"%@",[_collection_InformationCellData objectAtIndex:0]);
//Store the Objects from dictionary in temp Array.
NSArray *temp = [[_collection_InformationCellData objectAtIndex:indexPath.section] valueForKey:@"Cells"];
//Get the object based on Row Selection in UITableView.
NSLog(@"%@",[[temp objectAtIndex: indexPath.row] valueForKey:@"Text"]);
}
您需要使用Index访问数组并使用该对象中的键获取值。