小编Ken*_*yVB的帖子

如何制作枚举案例(swift)

我从ObjC那里得到了这个代码.我想将它转换为Swift,但是,我很难这样做......

ObjC代码:

navgivet.h

typedef NS_ENUM(NSInteger, BB3Photo) {
kirkenType = 10 ,
festenType = 20 ,
praestType = 30
};
@property (nonatomic, assign) BB3Photo selectedPhotoType;
Run Code Online (Sandbox Code Playgroud)

navgivet.m

- (IBAction)changeImage:(id)sender {
if ([sender isKindOfClass:[UIButton class]]) {
    UIButton *button = sender;
    _selectedPhotoType = button.tag;
}
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Vælg Billed"
                                                   delegate:self
                                          cancelButtonTitle:nil
                                     destructiveButtonTitle:nil
                                          otherButtonTitles:@"Vælg fra Biblioteket", @"Vælg Kamera", nil];
sheet.actionSheetStyle = UIActionSheetStyleDefault;
[sheet showInView:[self.view window]];
Run Code Online (Sandbox Code Playgroud)

}

switch (_selectedPhotoType) {
    case kirkenType: {
}break;
        case festenType: {
}break;
    case praestType: {
}break;
    default: …
Run Code Online (Sandbox Code Playgroud)

enums objective-c switch-statement swift ios8

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

UItabelview中的多个UICollection视图,包含 - swift

基本上,我试图获得类似于此结果的东西:http://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell

但是,我想要2个collectionsViews,第一部分为1,第二部分为另一个

我该如何实现这一目标?我在这里抨击我...每次我尝试设置委托和数据源它失败并说我需要注册一个笔尖我也不知道我如何将它的集合视图分开在它的cellForRowAtIndexPath中,我怎么能看到哪个一个正在加载?我怎样才能正确加载它,以便第一部分有self.genre,第二部分有self.radioStat

这是我第二次尝试设置委托和数据源时得到的错误

**由于未捕获的异常'NSInternalInconsistencyException'而终止app,原因:'无法使类型的视图出列:具有标识符CollectionViewCell34的UICollectionElementKindCell - 必须为标识符注册nib或类或在故事板中连接原型单元'**

tableViewCellCollectionView.swift

import Foundation
import UIKit
let collectionViewCellIdentifier: NSString = "CollectionViewCell"
class tableViewCellCollectionView: UITableViewCell  {

var collectionView: UICollectionView!

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)

    var layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsetsMake(4, 5, 4, 5)
    layout.minimumLineSpacing = 5
    layout.itemSize = CGSizeMake(91, 91)
    layout.scrollDirection = UICollectionViewScrollDirection.Horizontal
    self.collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
    self.collectionView.registerClass(collectionViewCellTableView.self, forCellWithReuseIdentifier: "CollectionViewCell")
    self.collectionView.registerClass(collectionViewCellTableView.self, forCellWithReuseIdentifier: collectionViewCellIdentifier)
    self.collectionView.backgroundColor = UIColor.lightGrayColor()
    self.collectionView.showsHorizontalScrollIndicator = false
    self.contentView.addSubview(self.collectionView)
    self.layoutMargins = UIEdgeInsetsMake(10, …
Run Code Online (Sandbox Code Playgroud)

uitableview ios uicollectionview swift

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

如何创建自定义UICollectionViewCell并从URL添加图像?

我想把我从flickr获得的图像加载到uicollectionsview我跟随分配指南但是当我必须这样做时它们都会分崩离析

    cell.imageView.image
Run Code Online (Sandbox Code Playgroud)

它基本上说它无法在uicollectionsviewcell的对象中找到imageView

我也试过这样的方法,但它没有用

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"flickerCell";

UICollectionViewCell *flickerCell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
flickerCell.backgroundColor = [UIColor whiteColor];
UIImageView *recipeImageView = (UIImageView *)[flickerCell viewWithTag:100];
recipeImageView.image = [UIImage imageNamed:[photoURLs objectAtIndex:indexPath.row]];
[flickerCell addSubview:recipeImageView];
return flickerCell;
}
Run Code Online (Sandbox Code Playgroud)

recipieImageView是我得到一些教程的东西.我的单元格在故事板中被命名为flickerCell,而且photURLs有33个我可以在代码中查看的对象.所以它就在那里.还有photoURLs是一个NSMutablearray.在这个方法中我的recipeImageView返回nill ??? 我有一个cell.h,它有imageView

#import <UIKit/UIKit.h>

@interface Cell : UICollectionViewCell
@property (strong, nonatomic) IBOutlet UIImageView *imageView;

@end
Run Code Online (Sandbox Code Playgroud)

所以,如果有人知道一种方式,我可以在uicollectionview中显示photoURLs所有的图像,这将是非常有帮助的

更新 我现在尝试了一种新方法,但仍然无法正常工作.imageView返回nil

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"flickerCell";

Cell *flickerCell = (Cell*) [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

flickerCell.backgroundColor = …
Run Code Online (Sandbox Code Playgroud)

objective-c uiimage ios uicollectionview uicollectionviewcell

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

switch语句出了错-快速的语言

在Obj-c中,我做了一个switch语句,我曾经使用UIsplitviewcontroller在iPad版应用程序中移动,现在我想快速执行相同操作...我尝试了几个小时,现在我唯一没有做过的事情能够尝试的是代码,因为它无论如何都会说某种编译错误,这就是我在Obj-c中得到的

-(void)initialSite:(int)viewId {
UIViewController *viewController;
switch (viewId) {
    case 0:{
        viewController = self.initital;
        NSString *star = [NSString stringWithFormat:@"Velkommen til %@'s  Bog",[data valueForKey:@"navn"]];
        self.navigationItem.title = star;}
        break;
    case 1:{
        viewController = self.startSide;
        NSString *start = [NSString stringWithFormat:@"%@'s  Bog, start-side",[data valueForKey:@"navn"]];
        self.navigationItem.title = start;}
        break;
}
[self showChildViewController:viewController];

}
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我很快想到的。对此我仍然很陌生,要理解它也有些困难,即使我有快速的编程语言书

这是我到目前为止迅速得到的

    let viewController = UIViewController()
switch viewController {
case "initial":
let initial : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc0 : UIViewController = initial.instantiateViewControllerWithIdentifier("initial") as UIViewController
self.presentViewController(vc0, animated: true, completion: nil) …
Run Code Online (Sandbox Code Playgroud)

switch-statement swift

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

UITableView到UICollectionView,而没有调用prepareForSegue

我还是有点新鲜的; 所以要温柔.我想从flickr下载一个setlist,然后选择以下设置并查看其图片.Sp远我已经签订了获得入围名单的方法.现在我希望能够单击其中一个设置列表并移动UICollectionsView并查看其图像.我需要帮助才能选择中的行UITableView.我想我在某个地方错过了一步,但似乎找不到我错过的洞.

无论如何这里是代码

- (void)viewDidLoad
{
    [super viewDidLoad];

self.tableView.rowHeight = 44;
photoURLs = [[NSMutableArray alloc] init];
photoSetNames = [[NSMutableArray alloc] init];
photoids = [[NSMutableArray alloc] init];
[self loadFlickrPhotos];

}
- (void)loadFlickrPhotos
{
// 1. Build your Flickr API request w/Flickr API key in FlickrAPIKey.h
NSString *urlString = [NSString stringWithFormat:@"http://api.flickr.com/services/rest/?method=flickr.photosets.getList&api_key=%@&user_id=%@&per_page=10&format=json&nojsoncallback=1", FlickrAPIKey, @"62975213@N05"];
NSURL *url = [NSURL URLWithString:urlString];
// 2. Get URLResponse string & parse JSON to Foundation objects.
NSString *jsonString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
//    NSDictionary …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios uicollectionview

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