小编Rya*_*los的帖子

核心数据 NSSet 返回空对象数组

更新:在我实现 Players 之前,我的游戏数据库中有没有玩家的幽灵条目。它返回的是那些条目而不是更新后的模型的最新条目

我正在努力让 Core Data 数据库正常工作,但在关系上遇到了一些麻烦。我对整个事情很陌生,所以不要把任何东西放在我身边,我什至可能不了解基础知识。但无论如何我们都要去。

这是我创建一个新游戏实体的地方。Players 是与已选择并存储在数组中的多个 Player 实体的 to-may 关系。

    Game *newGame = [NSEntityDescription insertNewObjectForEntityForName:@"Game" inManagedObjectContext:[SDDataManager dataManager].managedObjectContext];
    [newGame setGameType:@"multipleChoice"];
    [newGame setDate:[NSDate date]];
    NSSet *playersSet = [NSSet setWithArray:players];
    [newGame setPlayers:playersSet];
    [newGame setCards:[NSKeyedArchiver archivedDataWithRootObject:selectedCards]];

    NSError *error;
    [[SDDataManager dataManager].managedObjectContext save:&error];
    NSLog(@"New Game Error: %@",[error localizedDescription]);
Run Code Online (Sandbox Code Playgroud)

问题是,当我像这样从数据库中调用它时:

NSFetchRequest *requestSavedGame = [NSFetchRequest fetchRequestWithEntityName:@"Game"]; [requestSavedGame setFetchLimit:1];

NSError *error;
NSArray *loadedGame = [[SDDataManager dataManager].managedObjectContext executeFetchRequest:requestSavedGame error:&error];
NSLog(@"Load Game Error: %@",[error localizedDescription]);

Game *game = [loadedGame objectAtIndex:0];
NSLog(@"Players Set: %@",game.players);
NSLog(@"Players: %@",[game.players allObjects]);
Run Code Online (Sandbox Code Playgroud)

玩家:是空的??它准确地返回:

Players …
Run Code Online (Sandbox Code Playgroud)

iphone core-data ipad ios

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

点击标签栏时将桌面视图滚动到顶部

选择标签栏项时,我需要一直向上滚动表格视图.我试过这个,但它不起作用.

func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
    let tabBarIndex = tabBarController.selectedIndex
    if tabBarIndex == 0 {

        let indexPath = NSIndexPath(row: 0, section: 0)
        MyViewController().tableView.scrollToRow(at: indexPath as IndexPath, at: .top, animated: true)
    }
}
Run Code Online (Sandbox Code Playgroud)

调用该方法但tableView不会滚动到顶部.

uitableview tableview ios swift

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

类型'ViewController'不符合协议

我正在学习Swift并学习一些教程.我一直收到错误:输入

'ViewController'不符合协议'UITableViewDataSource'

import UIKit

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    var GetAllDataTest  = NSMutableArray()
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func viewWillAppear(_ animated: Bool) {

        GetAllDataTest = FMDBDatabaseModel.getInstance().GetAllData()
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "TestTableViewCell") as! TestTableViewCell
        //cell.editData = self
        cell.tag = indexPath.row
        var l = Tbl_Test()
        l = GetAllDataTest.object(at: indexPath.row) as! Tbl_Test

        cell.lblName.text! = l.Name
        cell.lblMobileNo.text! …
Run Code Online (Sandbox Code Playgroud)

xcode viewcontroller ios swift

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

如何在viewForHeaderInSection中的tableview中动态更改标题标题?

我需要在tableview标题中设置标题名称.我在代码中使用它

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section  function
{
   IView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
    UILabel *lbl_header = [[UILabel alloc]initWithFrame:CGRectMake(12, 0, tableView.bounds.size.width, 30)];
    lbl_header.tag=1000001;
    lbl_header.backgroundColor = [UIColor clearColor];
    lbl_header.textColor = [UIColor colorWithRed:204.0/255 green:204.0/255 blue:204.0/255 alpha:1.0];
    lbl_header.font = [UIFont fontWithName:@"Helvetica-Regular" size:20];

    ////  get the title name from subclass view controller 

    HOAViewController *obj_hoaview_controll = [[HOAViewController alloc]init];
    [obj_hoaview_controll fun_get_login_email_id];


    lbl_header.text = str_email_id1;//[udf_value objectForKey:@"StrEmailGet"];


    if (section == 0)
    {
         [headerView setBackgroundColor:[UIColor colorWithRed:102.0/255 green:102.0/255 blue:102.0/255 alpha:1.0]];
        //lbl_header.text = [udf_value objectForKey:@"StrEmailGet"];
    }
    else …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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

如何在 iOS Swift 3 中以编程方式设置元素视图中心?

我有一个视图,我想在其超级视图中水平和垂直居中。

我试过这个,但它不起作用:

let horConstraint = NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: view, attribute: .leading, multiplier: 1.0, constant: 0.0)
view.addConstraints([horConstraint]) 
Run Code Online (Sandbox Code Playgroud)

layout constraints ios autolayout swift

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

滚动时,tableview中的数据会堆积

如何在滚动不堆积时在tableViewCell中创建数据?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *theCell = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:theCell];

    if (! cell) {

        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:theCell];
    }

    UILabel *data1 = [self createLabelText:[NSString stringWithFormat:@"%@",[[arrayUtama objectAtIndex:indexPath.row]objectForKey:@"nomer"]]WithFrame:CGRectMake(10, 10, 150, 50) WithFont:[UIFont fontWithName:@"Arial" size:16] WithColor:[UIColor clearColor]];
    [cell insertSubview:data1 atIndex:0];

    UILabel *data2 = [self createLabelText:[NSString stringWithFormat:@"%@",[[arrayUtama objectAtIndex:indexPath.row]objectForKey:@"subjek"]]WithFrame:CGRectMake(50, 10, 150, 50) WithFont:[UIFont fontWithName:@"Arial" size:16] WithColor:[UIColor clearColor]];
    [cell insertSubview:data2 atIndex:1];

    UILabel *data3 = [self createLabelText:[NSString stringWithFormat:@"%@",[[arrayUtama objectAtIndex:indexPath.row]objectForKey:@"shadowScore"]]WithFrame:CGRectMake(200, 10, 150, 50) WithFont:[UIFont fontWithName:@"Arial" size:16] WithColor:[UIColor clearColor]];
    [cell insertSubview:data3 …
Run Code Online (Sandbox Code Playgroud)

objective-c uitableview ios

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

在我现有的硬币上添加硬币

我之前有一个类似的问题,但是添加分数却从未解决过,所以我想我现在就问它并同时修复这两个问题.我做了一个商店,人们可以在那里购买硬币,这些硬币将被添加到他们已有的硬币中.他们已经拥有的硬币可以通过以下方式加载:

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
NSString *loadcoins = [defaults objectForKey:@"savedcoins"];
[coinsdisplay setText:loadstring];
Run Code Online (Sandbox Code Playgroud)

我有一个按钮,你可以买100个硬币

-(IBAction)savecoins100:(id)sender { 
    NSString *savecoins = @"100"; 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    [defaults setObject:savecoins forKey:@"savedcoins"]; 
    [defaults synchronize];
}
Run Code Online (Sandbox Code Playgroud)

我想要的是新的字符串不是@"100"而是100 +以前的硬币现在这将是loadcoins但我不知道如何正确编码这可以有人帮助我吗?

谢谢

cocoa-touch objective-c nsuserdefaults ios

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