Tag: uikit

UITableView缺less新的可见行NSInternalInconsistencyException的单元格

我一直在与我的应用程序得到这个问题,不知道出了什么问题。 致命exception:NSInternalInconsistencyException缺less新的可见行78的单元格 这是堆栈跟踪: Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x191bbefd8 __exceptionPreprocess 1 libobjc.A.dylib 0x190620538 objc_exception_throw 2 CoreFoundation 0x191bbeeac +[NSException raise:format:] 3 Foundation 0x192656710 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 4 UIKit 0x198022b3c __46-[UITableView _updateWithItems:updateSupport:]_block_invoke.1049 5 UIKit 0x197d234b8 +[UIView(UIViewAnimationWithBlocks) _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:] 6 UIKit 0x197d39bac +[UIView(UIViewAnimationWithBlocks) animateWithDuration:delay:options:animations:completion:] 7 UIKit 0x197ee8770 -[UITableView _updateWithItems:updateSupport:] 8 UIKit 0x197eccfbc -[UITableView _endCellAnimationsWithContext:] 9 MyApp 0x1000ed518 -[UICommentsTableViewController insertNewComment:atLocation:] (UICommentsTableViewController.m:1228) […]

使用pipe理另外两个视图控制器的View Controller

我有一个offlineMapVC和一个onlineMapVC来支持在线地图(使用MapKit和Google地图)和离线地图(使用Route-Me )。 我做了我自己的mapVC来pipe理这些mapVCs的切换,并能够使用视图控制器作为一个单独的视图控制器。 好吧,我已经做了这个通过使我现在使用全新的mapVC的offlineMapVC和onlineMapVC实例variables。 首先,所有的东西似乎都起作用。 然而,当使用这种方法更长的时间,我遇到了一些问题,因为我在一个层次结构中使用视图控制器。 我读这是错误的路要走。 pipe理两个视图控制器之间切换的正确方法是什么? 我的问题似乎很简单,但我找不到一个体面的解决scheme。

在iOS中,可以通过alloc和initWithFrame添加一个UIButton?

button可以通过以下方式添加: UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; myButton.frame = CGRectMake(100, 100, 160, 50); [myButton setTitle:@"click me" forState:UIControlStateNormal]; [self.view addSubview:myButton]; 但是我们可以使用initWithFrame方法: UIButton *myButton2 = [[UIButton alloc] initWithFrame:CGRectMake(100, 300, 160, 50)]; //myButton2.buttonType = UIButtonTypeRoundedRect; myButton2.titleLabel.text = @"click me"; [self.view addSubview:myButton2]; 但上面的第2行被注释掉,因为它导致了一个“只读”属性的错误,并与该行注释,仍然没有任何button显示…可以添加一个UIButton,如果使用initWithFrame开始? ( 更新:我设置了一个黄色背景来查看视图的区域,并发现button2的标签文本实际上显示为“点击我”白色但触摸它没有视觉效果…所以我想知道更改代码示例2使其工作…)

目标c中带有三个button(带图标)的自定义单元格

我正在使用PSButtonCell的链接,但三个单独占用太多的空间,所以我试图创build一个自定义单元格与三个button在一行; 基本上像3个浮动图标。 我有一些代码用于创build一个带有图标的桌面视图,但是目前我不知道如何正确地分配它们(所有的图标都是重叠的),我不知道应该如何将视图添加到视图中。 这看起来像我可以修改做我想要的东西吗? 如果没有人有更好的解决scheme,他们可以为我提供? 非常感谢我的代码为图标 – (id)tableView:(id)tableView viewForHeaderInSection:(NSInteger)section { if (section == 1) { UIView *headerView = [[UIView alloc] initWithFrame:(CGRect){{0, 0}, {320, kHeaderHeight}}]; headerView.backgroundColor = UIColor.clearColor; headerView.clipsToBounds = YES; // icon UIImage *bugicon = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/Bug.png", kSelfBundlePath]]; UIImageView *bugiconView = [[UIImageView alloc] initWithImage:bugicon]; bugiconView.frame = (CGRect){{0, 21}, bugiconView.frame.size}; // bugiconView.center = (CGPoint){headerView.center.x, bugiconView.center.y}; […]

iOS中的Mutlitouch绘图

我正在和绘图工程一起工作,而且工作得很好,唯一的问题是,它只能用单点触摸工作。我想要做多点触摸绘图,所以如果用户用两个手指画,那么就应该绘制它们 下面是我的单触式绘图的代码 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; //LocationInView returns the current location of the reciever in coordinate system of the given View. m_previousPoint1 = [touch locationInView:self]; m_previousPoint2 = [touch locationInView:self]; m_currentPoint = [touch locationInView:self]; } -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { //AnyObject:- Returns one of the objects in the set, or […]

在iOS中使用线程返回图像

嗨,我正在通过斯坦福大学iOS开发课。 我有一个关于线程的问题。 我知道UIKit调用应该由主线程来处理。 我想知道这样的事情是否合法? – (UIImage *)mapViewController:(MapViewController *)sender imageForAnnotation:(id<MKAnnotation>)annotation { FlickrPhotoAnnotation *fpa = (FlickrPhotoAnnotation *) annotation; NSURL *url = [FlickrFetcher urlForPhoto:fpa.photo format:FlickrPhotoFormatSquare]; __block UIImage *image; dispatch_queue_t downloadQ = dispatch_queue_create("download queue", NULL); dispatch_async(downloadQ, ^{ NSData *data = [NSData dataWithContentsOfURL:url]; if (data) { dispatch_async(dispatch_get_main_queue(), ^{ image = [UIImage imageWithData:data]; }); } }); dispatch_release(downloadQ); return image; } 或者我应该返回NSData并处理调用方法中的所有线程? […]

UIKit Dynamics会通过碰撞来改变视图框架

我的项目有几个视图受到母视图中心的径向引力,以及弹性碰撞,因此它们不会重叠。 它工作的很好,但有时我需要调整视图的大小,而当视图变大时,其他视图必须离开视图,以使所有视图保持不重叠。 我期望碰撞行为能够意识到事情是触动的,并将它们分开,但似乎并非如此。 这就是我现在要做的: [UIView animateWithDuration:0.5 animations:^{ view.frame = CGRectInset(view.frame, -30, -30); } completion:^(BOOL finished) { [self.animator updateItemUsingCurrentState:view]; }]; 视图长得很好,animation代表被告知animation已经恢复,但其他视图不会移走。 新扩大的视图只是重叠(或根据z顺序underlaps)其他意见。 我试图改变而不是框架 – 没有骰子。 我试图从所有的行为中删除视图 – 没有骰子。 我尝试从animation师中删除一些和所有的行为 – 没有骰子。 我试图调用updateItemUsingCurrentState:在所有的意见 – 没有骰子。 我需要一些骰子! 你能帮我吗? 谢谢…(迅速,随意回答很快,我会翻译它)

当使用自定义布局时,sizeForItemAt方法不会调用

我为我的集合视图使用自定义布局,但如果我使用自定义布局sizeForItemAt方法不调用。 我的自定义布局: public class HorizontalCollectionViewLayout : UICollectionViewLayout { var itemSize = CGSize(width: 0, height: 0) { didSet { invalidateLayout() } } private var cellCount = 0 private var boundsSize = CGSize(width: 0, height: 0) public override func prepare() { cellCount = self.collectionView!.numberOfItems(inSection: 0) boundsSize = self.collectionView!.bounds.size } public override var collectionViewContentSize: CGSize { let verticalItemsCount […]

用高度信息迭代UIImage的各个像素

我正试图自动裁剪上面和下面有多余白色的图像。 我试图遍历图像的像素来find第一个非白色像素设置为从顶部裁剪适当的高度,然后使用最后一个非白色像素作为合适的高度从底部。 我试图使用CGBitmapContextGetData来生成单个像素,但据我所知,这只能保留图片的RGB颜色,所以像素高度的信息将丢失。 有谁知道任何方式遍历UIImage的个别像素,同时能够访问这些图片的高度信息? 谢谢。

为什么顺序UIViewanimation同时显示?

我已经写了一些代码,依次在屏幕上移动一些对象。 当每个对象完成移动,下一个开始。 代码的结构与此类似: 模型: moveObject { // Code to move the object … [delegate moved:self]; } 代表: moved:(MyClass *)o { UIView* v = [self viewForObject:o]; [UIView animateWithDuration:1.0 animations:^{ [v setCenter: [model center]]; } completion:^(BOOL finished){ // Move object [model moveObject]; }]; } 虽然代码似乎运行良好,但屏幕上发生的事情是,animation被分组为批次:大量的一次都发生,然后另一个组都开始。 如果我在[model moveObject];行放置一个断点[model moveObject]; 然后在没有任何animation被显示在屏幕上的情况下被finished设置为true几次。 然后,偶尔, finished将被设置为false ,并且在我让debugging继续之后,所有的animation将在屏幕上执行。 编辑 : 但是,如果我更改代码,以便在moveObject被调用时偶尔不移动对象,而是返回没有动作的对象,并且等待用户移动对象(并且因此通过委托的moved:select器调用回代码),那么animation的短串顺序发生。 ie问题似乎只发生在代码处于无限循环时。 怎么了?