Tag: 客观

如何创buildUICollectionView而不使用故事板?

我在网上find了一些很好的UIcollectionview教程 Beginning UICollectionView In iOS 6: Part 1/2 http://ashfurrow.com/blog/uicollectionview-example 没有故事板可以使用collectionview吗? 使用collectionview的故事板有什么优点和缺点?

在UICollectionView中以编程方式select项目

我有一个UICollectionViewController : – (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self.pageTastes count]; } – (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { CellTasteCollectionView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; Taste *taste = [self.pageTastes objectAtIndex:indexPath.item]; [[cell imageView] setImage:taste.image]; [cell setObjectId:taste.objectId]; return cell; } 有用。 我有这个viewDidLoad ,允许用户select多个项目: [self.collectionView setAllowsMultipleSelection:YES]; 我想要的是,第一次加载CollectionView,一些项目被选中编程,基于它们在CellTasteCollectionView objectId 。 以下是我如何做到这一点: – (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ Taste *taste = [self.pageTastes […]

如何删除UITableView中的箭头

我正在研究一个UITableView 。 请告诉我如何删除显示在每一行的箭头button?

在cellForRowAtIndexPath中调用heightForRowAtIndexPath?

所以,似乎在cellForRowAtIndexPath之前调用了heightForRowAtIndexPath 。 我目前正在使用cellForRowAtIndexPath来计算每个单元格的高度(他们是variables的高度,使用UILabel不同的文本量。 我很困惑如何设置单元格的高度是否正确,如果设置高度的方法是在计算它的方法之前调用的。 我创build了一个NSString的类别,和另一个UILabel ,它们一起使UILabel成为正确的大小。 问题是包含这些标签的UITableViewCell实例没有被resize,所以标签挂在每个标签的末尾,重叠在下面。 我知道我需要做的是使单元格的高度与标签的高度相等,再加上一些额外的空白空间,但是我很疑惑如何在标签高度计算之前设置高度。 我可以在不使用heightForRowAtIndexPath情况下设置某个人的身高吗? 或者如果不是,我可以计算其他地方的细胞高度吗? 我正在使用indexPath.row来实现这一点,所以事先做好会很棘手。 这是我的cellForRowAtIndexPath代码: 的cellForRowAtIndexPath – (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath { FQCustomCell *_customCell = [tableView dequeueReusableCellWithIdentifier: @"CustomCell"]; if (_customCell == nil) { _customCell = [[FQCustomCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: @"CustomCell"]; } _customCell.myLabel.text = [[_loadedNames objectAtIndex: indexPath.row] name]; _customCell.myLabel.font = [UIFont fontWithName: […]

如何dynamic设置UITableView的高度?

我有一个tableview与不同的单元格高度使用heightForRowAtIndexPath:方法。 我想dynamic设置UITableView的高度。 目前,我正在使用viewDidLoad方法设置tableView的维度: self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 770, 310, 400)]; self.tableView.dataSource = self; self.tableView.delegate = self; 我想也许我可以添加这个: self.tableView.contentSize.height; 但是问题当然是内容大小只能在表格加载后计算,所以如果我把它放进去 self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(10, 770, 310, self.tableView.contentSize.height)]; 它不工作。 – (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *description = [photosFromCommentsArray objectAtIndex:indexPath.row]; // NSLog(@"description is %@",description); if(description == (id)[NSNull null]) { return 70; } else { return […]

为什么当我的UITableView尝试加载时出现无法出队的错误?

我得到以下错误: *由于未捕获的exception“NSInternalInconsistencyException”而终止应用程序,原因:'无法使用标识符FontCell出列单元 – 必须为该标识符注册一个nib或一个类,或者在故事板中连接一个原型单元格' 我不确定我做错了什么。 我设置了单元格标识符(以编程方式,因为它不是通过Interface Builder创build的),并且尽我所能在委托方法中做了所有事情,但是当我试图加载UITableView时,我仍然遇到了这个错误。 这里是相关的代码(值得注意的是我已经为自定义选项分类了UITableViewCell): – (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } – (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return self.fonts.count; } – (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"FontCell"; FontCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath]; if (!cell) { cell = [[FontCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FontCell"]; cell.selectionStyle = UITableViewCellSelectionStyleNone; } int […]

iOS同时向多个蓝牙设备播放audio

我有一些蓝牙扬声器(类似的) ,并且真的很想能够同时播放其中的一个以上,但是我找不到一个办法。 我可以部署我自己的应用程序,所以它不一定要通过公共API来完成,但iPhone硬件是否支持它?

为UITableView调用beginUpdates / endUpdates有什么好处,而不是这样做?

我有一个数组,我正在使用的表视图的数据源的数组。 有一次,我可能不得不对这个数据结构做一些复杂的修改。 (例如,我可能需要做的一系列操作是:在这里删除一行,在那里插入一行,在这里插入一个部分,删除另一行,插入另一行,删除另一行,插入另一部分 – 你得到想法)。如果对于序列中的每个操作,我只是更新数据源,然后立即为表视图执行相应的更新,这很容易做到。 换句话说,伪代码看起来像: [arrayOfArrays updateForOperation1]; [tableView updateForOperation1]; [arrayOfArrays updateForOperation2]; [tableView updateForOperation2]; [arrayOfArrays updateForOperation3]; [tableView updateForOperation3]; [arrayOfArrays updateForOperation4]; [tableView updateForOperation4]; // Etc. 但是,如果我要在beginUpdates / endUpdates“块”中包含这些操作,则此代码不再有效。 为了看清楚为什么,从空表视图开始成像,并在第一部分的开始依次插入四行。 这里是伪代码: [tableView beginUpdates]; [arrayOfArrays insertRowAtIndex:0]; [tableView insertRowAtIndexPath:[row 0, section 0]]; [arrayOfArrays insertRowAtIndex:0]; [tableView insertRowAtIndexPath:[row 0, section 0]]; [arrayOfArrays insertRowAtIndex:0]; [tableView insertRowAtIndexPath:[row 0, section 0]]; [arrayOfArrays insertRowAtIndex:0]; [tableView […]

AVCaptureSession stopRunning方法创build可怕的挂起

使用来自iOS7教程第22章的Ray Wenderlich的QRCode阅读器 ,我成功阅读了当前应用程序的QRCodes。 我现在扩展它,成功读取一个QRCode,我想要存储的AVMetadataMachineReadableCodeObject读取AVMetadataMachineReadableCodeObject , AVMetadataMachineReadableCodeObject到一个新的视图,并在新的视图上使用该数据,或多或less大多数QRCode阅读器应用程序像RedLaser等)处理条形码和QRCodes。 但是,我调用[captureSession stopRunning] (这样它不会再读取QRCodes并触发更多的细节),并且有10多秒的挂起。 我试图通过这个SO问题来实现一个async调用,但无济于事。 我也看了这些 SO 问题 ,似乎不适合这个目的。 有没有人有一个想法如何消除这挂? 这里是代码: #import "BMQRCodeReaderViewController.h" #import "NSString+containsString.h" #import "BMManualExperimentDataEntryViewController.h" @import AVFoundation; @interface BMQRCodeReaderViewController () <AVCaptureMetadataOutputObjectsDelegate> @end @implementation BMQRCodeReaderViewController { AVCaptureSession *_captureSession; AVCaptureDevice *_videoDevice; AVCaptureDeviceInput *_videoInput; AVCaptureVideoPreviewLayer *_previewLayer; BOOL _running; AVCaptureMetadataOutput *_metadataOutput; } – (void)setupCaptureSession { // 1 if (_captureSession) return; // 2 […]

如何根据文本标签长度dynamic设置表格单元高度?

我正在学习Obj-C和iOS编程,但我还是很新的。 我决定尝试做一个简单的Reddit客户端应用程序。 我试图显示在UITableView ,每个职位由自己的单元格表示的首页文章。 在单元格上,这是我如何设置标题: cell.textLabel.numberOfLines = 0; cell.textLabel.text = [[tempDictionary objectForKey:@"data"] objectForKey:@"title"]; [cell.textLabel sizeToFit]; 但是,如果标题文本太长,单元格会自动裁剪。 这是一张图片: 如何使我的单元格自动调整高度以适应更长的标题标签,而不会与其他单元格或细节文本标签相交? 感谢您的任何帮助!