我正在尝试将数据从集合视图控制器传递到表视图控制器,但是当我认为一切正常时会出现此问题.. 无法识别的选择器发送到实例我的代码是这样的:< / p>
ViewController.m(集合视图控制器)
#import "ViewController.h"
#import "ColViewCell.h"
#import "DetailViewController.h"
@interface ViewController ()
{
// Private member varibles
NSArray *_arrayOfImages;
NSArray *_arrayOfNames;
// Array de ingredientes
NSArray *_arrayOfCeviche;
NSArray *_arrayOfTacacho;
NSArray *_arrayOfAnticucho;
NSArray *_arrayOfPapita;
NSArray *_arrayOfParihuela;
NSArray *_arrayOfLomo;
NSArray *_arrayOfIngredients;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// Array que contiene los titulos
_arrayOfNames = @[@"Anticucho", @"Arroz Chaufa", @"Cebiche", @"Pachamanca", @"Papa a la Huancaina", @"Parihuela", @"Picante de cuy", @"Tacacho con cecina", @"Pollo a la brasa", @"Lomo saltado"];
// Array que contiene las imagenes
_arrayOfImages = @[@"Anticucho.jpg", @"chaufa.jpg", @"ceviche.jpg", @"pachamanca.jpg", @"papita.jpg", @"parihuela.jpg", @"cuy.jpg", @"tacacho.jpg", @"brasa.jpg", @"lomo.jpg"];
// Arrays que de los ingredientes
_arrayOfCeviche = @[@"Quesito", @"Limon", @"Choclito", @"Cocinita", @"La lechesita", @"La miradita", @"La weuabdita", @"La cagada", @"Ptm Toy Jodido XD", @"Que emoción", @"Wiiiiiii"];
_arrayOfLomo = @[@"Que novedada", @"jajajaja que buena", @"Lukita", @"losisisisi", @"maniserio", @"joder", @"joselet", @"lskadlkdl", @"bah"];
_arrayOfPapita = @[@"que buena!", @"csm!!", @"que genio!", @"novedades", @"que rico!!", @"coger delicisioso", @"Mffffff"];
_arrayOfParihuela = @[@"Un culaso", @"Chambon", @"Noveades", @"que hacer", @"asu macho", @"Espero que este bien", @"Así es la vida la chamba", @"Debo aprender mas!!"];
_arrayOfTacacho = @[@"Tacachin", @"Lalilinnn", @"Masinisn", @"Joder", @"Ojojoojojo", @"Lista hermosa!"];
_arrayOfAnticucho = @[@"Me encanta Objective-c", @"Hermosisimo", @"Me encanta xcode!", @"Que hermoso es esto", @"Debe ser un chambon total", @"jajajaja novedades", @"Lol supremo"];
***NSArray that contains all the arrays***
_arrayOfIngredients = @[_arrayOfCeviche, _arrayOfLomo, arrayOfAnticucho, _arrayOfParihuela, _arrayOfTacacho, _arrayOfPapita];
}
我的方法是将数据从我的集合视图传递到表格视图
// Method to pass data from a view to another view
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"]) {
NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0];
DetailViewController *dvc = [segue destinationViewController];
dvc.Titulos = [_arrayOfIngredients objectAtIndex:indexPath.item];
}
}
我的DetailViewController.h(表视图控制器)
#import <UIKit/UIKit.h>
@interface DetailViewController : UITableViewController
@property (strong, nonatomic) NSString *Titulos;
@end
我的DetailViewController.m(表视图控制器)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
***Xcode tell me this line is the problem...***
cell.textLabel.text = self.Titulos;
return cell;
}
我的代码有什么问题??? U.u
答案 0 :(得分:4)
dvc.Titulos = [_arrayOfIngredients objectAtIndex:indexPath.item];
如果_arrayOfIngredients
是包含多个NSArray对象的NSArray,那么您将数组传递到 Titulos 对象中。
Titulos 是一个NSString,因此当UILabel尝试访问NSString上的- length
属性时,会发生崩溃,因为 Titulos 是NSArray而不是的NSString。
在你的DetailViewController上,我假设你想从你的_arrayOfIngredients传入一个子数组。
#import <UIKit/UIKit.h>
@interface DetailViewController : UITableViewController
@property (strong, nonatomic) NSArray *Titulos;
@end
然后,您必须像ViewController一样配置DetailViewController,但使用 Titulos 数组。
答案 1 :(得分:2)
NSArray
没有回复length
,它会回复count
。在以下行中:
dvc.Titulos = [_arrayOfIngredients objectAtIndex:indexPath.item];
您正在将NSArray
传递给带有NSString
的属性,因此它会在某个时刻尝试获取字符串的长度,而是调用length
方法<{1}}对象,它没有响应,所以它崩溃了。
答案 2 :(得分:1)
检查代码:
for (int j=0; j<enumKeyReferenceArray.count; j++) {
NSString *attri =[enumKeyReferenceArray valueForKey:@"BeltCondition"];
}
问题是我忘了告诉编译器我需要哪个索引元素。
正确的行应该是:
NSString *attri =[enumKeyReferenceArray[j] valueForKey:@"BeltCondition"];
答案 3 :(得分:0)
我有一个NSArray * dataArray来填充tableView
导致我问题的是我使用
self.dataArray = [NSArray arrayWithObject:anotherArray];
我应该做的是
self.dataArray = [NSArray arrayWithArray:anotherArray]
因此,在您的情况下,您应该检查dataArray中包含的内容
答案 4 :(得分:0)
在我的情况下,问题是来自API的数据 数据是:
x64
并在通过NSJSONSerialization转换为NSDictionary后,它是
{
"status": true,
"message": "Order listed successfully.",
"data": [
{
"order_id": "9",
"restaurant_name": "Demo Restaurant",
"payment_token": "Test162R25892",
"payment_status": "Approved",
"subtotal": "480.00",
"final_amount": "561.00",
"vat": "57.00",
"service_fee": "24.00",
"delivery_fee": "0.00",
"discount": "0.00",
"customer_type": "member",
"created": "2016-02-28 12:17:21",
"order_status": "complete"
}
]
}
我只是错过了[{1}}中的括号和(在Dict中,数据内部并将其解析为
{
data = (
{
created = "2016-02-28 12:17:21";
"customer_type" = member;
"delivery_fee" = "0.00";
discount = "0.00";
"final_amount" = "561.00";
"order_id" = 9;
"order_status" = complete;
"payment_status" = Approved;
"payment_token" = Test162R25892;
"restaurant_name" = "Demo Restaurant";
"service_fee" = "24.00";
subtotal = "480.00";
vat = "57.00";
}
);
message = "Order listed successfully.";
status = 1;
}
发生异常,因为我试图将数组值发送到标签文本。只需仔细查看您正在处理的数据。
答案 5 :(得分:0)
就我而言,其中一个豆荚有问题。已用pod update
修复。