- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我的问题很严重,不适用于那些只愿意提供负面反馈或只是为了编辑和获得奖励目的的人。
我的问题很难传达,但我正在尽力传达完整的问题。实际上我在后端有两个 TableView 和两个 Json 文件,以及一个 AVPlayerViewController。首先,firstTableViewController 显示第一个 json 文件,其中包含以下 Json 数据
[{
"id": "0",
"name": "Religion"
}, {
"id": "1",
"name": "News"
}, {
"id": "2",
"name": "Sport"
}, {
"id": "3",
"name": "Doc"
}, {
"id": "4",
"name": "Kids"
}, {
"id": "5",
"name": "Music"
}, {
"id": "6",
"name": "Movie"
}, {
"id": "7",
"name": "Entr"
}, {
"id": "8",
"name": "Cooking"
}, {
"id": "9",
"name": "All"
}]
在 SecondViewController 中,提取包含不同链接的 second Json file 以及上面第一个 json 文件中提到的类别。在我的应用程序中成功检索了两个 Json 文件的数据。
当我单击 FirstTableViewController 的任何单元格(包含特定类别)时,它会将我带到第二个TableViewController,其中包含包含该特定类别(名为 category_name
)的所有对象的 title
属性> 在第二个 json 文件中)选择的类别。到目前为止,一切都非常酷。但是当我过去单击任何标题时出现的问题应该将我带到 AVPlayerViewController 并播放相关的直播链接。但它给了我以下错误,
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSArrayM objectAtIndex:]: index 2097174 beyond bounds [0 .. 32]' *** First throw call stack: ( 0 CoreFoundation 0x0000000104b0234b __exceptionPreprocess + 171 1 libobjc.A.dylib
0x000000010456321e objc_exception_throw + 48 2 CoreFoundation
0x0000000104a33f1b -[__NSArrayM objectAtIndex:] + 203 3 AlbTVRadio 0x00000001022bcae1 -[Second prepareForSegue:sender:] + 321 4 UIKit 0x0000000102bbef5f -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 353 5 UIKit 0x0000000102bbedcd -[UIStoryboardSegueTemplate _perform:] + 82 6
UIKit 0x0000000102bbf08f -[UIStoryboardSegueTemplate perform:] + 156 7 UIKit 0x000000010253b52a -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1769 8 UIKit 0x000000010253b78d -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 330 9 UIKit 0x00000001023f12eb _runAfterCACommitDeferredBlocks + 320 10 UIKit 0x00000001023ddf6f _cleanUpAfterCAFlushAndRunDeferredBlocks + 566 11 UIKit 0x000000010240f3da _afterCACommitHandler + 176 12 CoreFoundation 0x0000000104aa6e17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 13 CoreFoundation 0x0000000104aa6d87 __CFRunLoopDoObservers + 391 14 CoreFoundation 0x0000000104a8bb9e __CFRunLoopRun + 1198 15 CoreFoundation
0x0000000104a8b494 CFRunLoopRunSpecific + 420 16 GraphicsServices
0x0000000106784a6f GSEventRunModal + 161 17 UIKit
0x00000001023e4964 UIApplicationMain + 159 18 AlbTVRadio
0x00000001022cd65f main + 111 19 libdyld.dylib
0x000000010a00968d start + 1 20 ???
0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException
我认为问题出在 segue 代码中,即没有选择准确的 ChannelObject
或 Object.livestream
这是我的第二个 viewController 的代码。其中包含第二个 json 文件。所以请尽可能更正此代码。
#import "Second.h"
#import "Channel.h"
#import "UIImageView+AFNetworking.h"
#import "Type.h"
#define getDataUrl @"https://creativestudy.000webhostapp.com/webservices/test.json"
@interface Second ()
@end
@implementation Second
@synthesize tvArray,currentObject;
- (void)viewDidLoad {
[super viewDidLoad];
[self retrieveData];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return tvArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cells" forIndexPath:indexPath];
Channel * ChannelObject;
ChannelObject = [tvArray objectAtIndex:indexPath.row];
cell.textLabel.text = ChannelObject.channelTitle;
cell.detailTextLabel.text = ChannelObject.channelLivestream;
cell.detailTextLabel.hidden = YES;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
NSURL *url = [NSURL URLWithString:ChannelObject.channelImage];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
UIImage *placeholderImage = [UIImage imageNamed:@"placeholder"];
__weak UITableViewCell *weakCell = cell;
[cell.imageView setImageWithURLRequest:request placeholderImage:placeholderImage success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weakCell.imageView.image = image;
[weakCell setNeedsLayout];
} failure:nil];
// Configure the cell...
return cell;
}
-(void) getType:(id)typeObject{
currentObject = typeObject;
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"playVideo"]) {
AVPlayerViewController *playerViewController = [segue destinationViewController];
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
Channel * ChannelObject;
ChannelObject = [self.tvArray objectAtIndex:(int)indexPath];
NSURL *liveUrl = [NSURL URLWithString:ChannelObject.channelLivestream];
playerViewController.player = [AVPlayer playerWithURL:liveUrl];
[playerViewController.player play];
}
}
-(void) retrieveData{
NSURL * url = [NSURL URLWithString:getDataUrl];
NSData * data = [NSData dataWithContentsOfURL:url];
NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
tvArray = [[NSMutableArray alloc] init];
for (int i = 0; i < jsonArray.count; i ++)
{
NSDictionary *aCategoryJSON = [jsonArray objectAtIndex:i];
NSString *cId = [aCategoryJSON objectForKey:@"id"];
NSString *cTitle = [aCategoryJSON objectForKey:@"title"];
NSString *cCategory = [aCategoryJSON objectForKey:@"category_name"];
NSString *cImage = [aCategoryJSON objectForKey:@"image"];
NSString *cLivestream = [aCategoryJSON objectForKey:@"livestream"];
NSString *cWebsite = [aCategoryJSON objectForKey:@"Website"];
if (cCategory == currentObject.typeName){
[tvArray addObject:[[Channel alloc] initWithChannelId:cId andChannelTitle:cTitle andChannelCategory:cCategory andChannelImage:cImage andChannelLivestream:cLivestream andChannelWebsite:cWebsite]];
}
else if ([currentObject.typeName isEqualToString: @"All"]){
[tvArray addObject:[[Channel alloc] initWithChannelId:cId andChannelTitle:cTitle andChannelCategory:cCategory andChannelImage:cImage andChannelLivestream:cLivestream andChannelWebsite:cWebsite]];
}
}
[self.tableView reloadData];
}
@end
最佳答案
你的问题在这里:
ChannelObject = [self.tvArray objectAtIndex:(int)indexPath];
您已将一个对象(NSIndexPath
的实例)转换为 int,并且 Objective-C 允许您这样做,因为它基于 C,尽管这没有任何意义。
indexPath
是指向内存中对象的指针,因此当您将其转换为 int
时,您会得到一个解释为整数的内存地址,这就是为什么您会看到尝试访问数组中的元素 2097174。大概您将强制转换添加到 int
中,因为编译器告诉您不能在该函数中使用 indexPath。
您需要做的是使用 indexPath.row
从 NSIndexPath
实例获取行整数。您还可以使用更现代的数组访问语法和小写字母来启动变量(大写字母用于类):
Channel *channelObject = self.tvArray[indexPath.row];
关于ios - 如何在 prepareForSegue 方法中访问对象数组中选定对象的不同属性或特性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42359382/
我有十二个指向不同类别的链接。作为用户定位的一种方式,我想强调用户现在所在的类别( - 按钮)。 如何在 CSS 中实现这一点?我读到了 selected和 active ,但我还没能让它发挥作用。
我想通过单击按钮来获取选择框中的所有选项值(选定/未选定)。我怎样才能做到这一点? 最佳答案 我认为这是使用 Traversing/map 的好机会方法: var valuesArray = $("#
我正在尝试构建一个计算器,其中包含两个数字的两个 TextView 字段。我弄清楚了如何使用“应用程序内”数字键盘输入顶部数字 Operand 1 [textView] 的数字(我知道使用 EditT
我有一个简单的 jQuery $("span.value"),它选择包含文本的节点。此文本保证为整数。如何计算所有选定节点文本的总和,并将总和放入另一个节点? 3 4 5 ? 最佳答案 你可以这样做:
我从同一台服务器上托管的一堆数据库中备份了 mysql 数据库 db1。现在只需要备份具有访问 db1 权限的选定用户,以便我可以在 db1 还原之前将这些特权用户还原到我的新服务器。 最佳答案 St
我有一个 ListView 。我想添加一个动画,如果我选择一个列表项,它将被删除,并且该项目下方的其余项目将通过向上滑动动画向上移动。我已经通过获取其子位置使用线性布局完成了此操作,但我无法理解如何向
我不明白如何使用 Python 解析来自 Outlook 的突出显示(选定)邮件? 我有这个代码,但它适用于上一封邮件。 import win32com.client outlook = win32c
在 Xcode 6 中,您现在可以为选项卡项目的选中和未选中状态设置图标。请参阅下图中的说明: 和 唯一的问题是 SELECTED 状态的图像不显示。它只是显示空白。还有其他人有这个问题吗?请看下面的
在我的数据模型中,我有一个实体组和另一个GroupMember实体。一个Group包含一个或多个GroupMembers,但一个GroupMember只能同时位于一个Group中。到目前为止没有问题,
Android Button 在不同状态(正常、按下、选中、禁用)之间移动时会更改其可绘制背景。背景切换是即时的。是否可以使其平滑(动画)? 最佳答案 是的,这是可能的。您只需为按钮添加 addAni
我使用 emacs 来查看和编辑代码和其他文本文件。我想知道是否有一种方法可以向前或向后搜索当前缓冲区中标记的文本。类似于我在记事本或写字板中可以执行的操作。就像我可以在缓冲区中标记一些文本并执行 C
如何根据状态(选定、禁用)设置自定义选择类?如何根据状态选择(选定、禁用)在自定义下拉列表中设置类?照做了,但什么也没发生。请看我的例子................................
我正在尝试检查下拉菜单中是否存在特定文本值,如果存在,我想将其属性设置为selected。 我成功编写了一个 if 语句来检查文本是否存在: var country = usr.location; i
对于我的应用程序,我想让用户能够在回收器 View 中调整 TextView 项目的文本大小(通过捏缩放或 SeekBar)。默认值应为系统设置中选择的文本大小。最小值应为系统设置中的“非常小”,最大
我正在尝试创建一个 ListBoxItem 模板,该模板在选择时将带有圆角边框。我得到了这个 xaml,它在选择时不起作用:
我正在寻找检索焦点元素的 HTML。查看 webdriver.io 文档,方法 .getActiveElement() 应该可以解决这个问题。但是,我的 IDE (WebStorm) 显示错误,指出它
我创建了一个圆,在我的 onDraw() 方法中围绕圆绘制了一条字符串和一条线(箭头)。 public class Circle extends Activity { public class
对于生产应用程序,我们希望在 Windows 窗体应用程序的 ElementHost 内显示 DatePicker,但我们遇到了 SelectedDate 和 CurrentDate 不可读的问题,因
好的,我在此处和 Google 上的许多网站上搜索了此问题的结果,但找不到针对我的问题的确切解决方案。 我有一个 sql 提取姓名和办公室。所以事情是这样的: $sql = "SELECT m
选中单元格时如何改变灰色? 最佳答案 当用户点击选中的行 (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSInd
我是一名优秀的程序员,十分优秀!