小编Jus*_*ral的帖子

UICollectionView数据源方法未被调用,但正在init中设置

这是我的源代码

- (id)initWithCollectionView:(UICollectionView *)collectionView
{
self = [super init];

if (self)
{
    self.collectionView = collectionView;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    [self.collectionView registerClass:[TWNTweetCell class] forCellWithReuseIdentifier:kCell];
    self.collectionViewLayout = self.collectionView.collectionViewLayout;



    self.tweetArray = @[];
    self.tweetTextArray = @[];

    self.twitter = [STTwitterAPI twitterAPIOSWithFirstAccount];
}

return self;
}

#pragma mark - CollectionView
#pragma mark DataSource

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:      (NSInteger)section
{
return [self.tweetArray count];
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
TWNTweetCell *cell = (TWNTweetCell *)[collectionView dequeueReusableCellWithReuseIdentifier:kCell forIndexPath:indexPath];

NSDictionary …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview

12
推荐指数
2
解决办法
3万
查看次数

如何使用Facebook Pop Animation Framework动画UIView图层背景颜色?

Facebook刚开源他们的真棒POP动画框架,它是由Core Animation构建的,我无法弄清楚如何为图层背景颜色设置动画.

这是我的代码:

POPBasicAnimation *colorAnimation = [POPBasicAnimation animation];
colorAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewBackgroundColor];

if (_pressed)
{
    colorAnimation.toValue = (id)[UIColor redColor].CGColor;
}
else
{
    colorAnimation.toValue = (id)[UIColor greenColor].CGColor;
}

[_button pop_addAnimation:colorAnimation forKey:@"colorAnimation"];
Run Code Online (Sandbox Code Playgroud)

.toValue应该只接受NSNumberNSValue但我无法弄清楚如何在色彩传递给动画作为.toValue.

有人知道吗?

animation core-animation objective-c ios facebook-pop

4
推荐指数
1
解决办法
3401
查看次数

具有arc4random()的余数运算符和数组的计数导致"无法找到过载"错误

这段代码

    var randomNumber: Int = arc4random() % nameArray.count
Run Code Online (Sandbox Code Playgroud)

给我错误"无法找到接受提供的参数的'%'的重载"

我仍然试图习惯语法并阅读文档,但似乎无法想出这个.有人可以帮忙吗?

types compiler-errors swift

3
推荐指数
1
解决办法
1602
查看次数

如何在视图加载时预先选择 UITableViewCell?

我正在研究在表格视图中选择单元格时播放声音的东西。tableView 由带有声音名称的 NSString 数组填充。

我有一个对象作为控制器的一部分,它有一个声音对象,当您单击单元格时,它会播放声音对象的正确文件名称。

如何在视图首次加载时预先选择一个 TableView 单元格,并让它在 tableView 首次加载时不播放声音。

这是我目前的选择代码。

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
TMVSoundCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SoundCell" forIndexPath:indexPath];

[self configureCell:cell forRowAtIndexPath:indexPath];

return cell;
}

- (void)configureCell:(TMVSoundCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.soundTitle.text = [[self.soundArray objectAtIndex:indexPath.row]name];


if (self.selectedRowIndexPath != nil && [indexPath compare:self.selectedRowIndexPath]    == NSOrderedSame)
{
           cell.soundTitle.textColor = [UIColor whiteColor];
           self.itemView.item.sound = [self.soundArray objectAtIndex:indexPath.row];

    [DataManager saveContext];
}

else
{
        cell.soundTitle.textColor = AppDelegate.atmosphere.currentColor;
}


}


#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSMutableArray *indexPaths …
Run Code Online (Sandbox Code Playgroud)

iphone objective-c uitableview ios

2
推荐指数
2
解决办法
3411
查看次数

如何在Swift中从数组中提取随机项?

我试图从数组中拉出一个随机项.当我运行时,在拉随机项并给我这个错误"EXC_BAD_INSTRUCTION"之间大约50/50.知道发生了什么事吗?

现在我的代码看起来像这样:在解决方案之前

   func randomCard() -> Card {
    let randomIndex = Int(arc4random()) % cardArray.count
    let randomCard = cardArray[randomIndex]

    cardArray.removeAtIndex(randomIndex)

    return randomCard
}
Run Code Online (Sandbox Code Playgroud)

   func randomCard() -> Card {

    let randomIndex = arc4random_uniform(UInt32(cardArray.count))
    let randomCard = cardArray[randomIndex.hashValue]

    cardArray.removeAtIndex(randomIndex.hashValue)

    return randomCard
}
Run Code Online (Sandbox Code Playgroud)

这就是我现在正在使用的,似乎正在工作.谢谢大家的帮助.

ios exc-bad-instruction swift

2
推荐指数
1
解决办法
3461
查看次数

如何使用UIBezierPathwithArcCenter在iOS中绘制完整的圆圈?

我希望startAngle处于90度,即π/ 2,所以我想如果我将endAngle设为90度,那么它只会形成一个完整的圆,但是没有绘制任何东西.

当我将开始和结束角度设置为如下所示的不同程度时,绘制路径,但它不是一个完整的圆.

下面是我目前使用的代码,但是如果startAngle是90度以便绘制一个完整的圆圈,我似乎无法弄清楚endAngle应该是什么.

有人可以帮忙吗?

    override func drawRect(rect: CGRect) {
    let center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
    let radius: CGFloat = max(bounds.width, bounds.height)
    let startAngle: CGFloat = 3 * ? / 4
    let endAngle: CGFloat = ? / 4

    var path = UIBezierPath(arcCenter: center,
                               radius: bounds.width / 2 - arcWidth / 2,
                           startAngle: startAngle,
                             endAngle: endAngle,
                            clockwise: true)


    path.lineWidth = arcWidth
    path.lineCapStyle = kCGLineCapRound
    counterColor.setStroke()
    path.stroke()
}
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch ios uibezierpath swift

1
推荐指数
1
解决办法
1165
查看次数