小编sir*_*333的帖子

如何使用UIScrollView以编程方式强制滚动?

我有一个水平的 UIScrollview设置(意思是它不是向上和向下滚动但只向左滚动的一个)并且在应用程序启动时,我希望这个滚动视图向左滚动,然后向右滚动 - 有点"展示"它滚动的能力 - 然后最后停止,然后让用户接管并用手指手动控制滚动.一切正常 - 除了这个有载的左右演示滚动.

我没有使用Interface Builder,我正在用代码做任何事情:

//(this is in viewDidLoad:)
// Create the scrollView:
UIScrollView *photosScroll = [[UIScrollView alloc] initWithFrame: CGRectMake(0, 0, 320, 200)];
[photosScroll setContentSize: CGSizeMake(1240, 200)]; 
// Add it as a subview to the mainView
[mainView addSubview:photosScroll];


// Set the photoScroll's delegate: 
photosScroll.delegate = self;

// Create a frame to which to scroll:   
CGRect frame = CGRectMake(10, 10, 80, 150);
// Scroll to that frame:
[photosScroll scrollRectToVisible: frame animated:YES];
Run Code Online (Sandbox Code Playgroud)

所以scrollView加载成功,我可以用我的手指左右滚动它 - 但它不会像我希望的那样"自动滚动".

  • 我尝试在将scrollView添加为子视图之前和之后调用scrollRectToVisible …

iphone uiscrollview uikit ios

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

使用Objective-C API获取Youtube频道播放列表

我正在尝试使用Google的Objective-C Youtube API来获取youtube频道的播放列表 - 没有运气.

- 我从以下网址下载了Google的官方API:http: //code.google.com/p/gdata-objectivec-client/source/browse/#svn%2Ftrunk%2FExamples%2FYouTubeSample

但示例应用程序并没有真正做任何事情 - 它甚至不是iOS示例应用程序.似乎是一个Mac OS应用程序.它的Read-Me文件说:"这个示例应该自动构建并复制GTL.framework,作为构建和运行过程的一部分."

好的......然后是什么?

你如何在iPhone应用程序中使用它?

我没有找到任何实际的指示来完成这项工作.

知道我们应该在这做什么吗?

youtube iphone objective-c gdata

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

从Bundle复制文件时Swift FileManager错误

我正在尝试将我的App的Bundle中的文件复制到设备上,我收到一个奇怪的错误: cannot convert the expression type '$T5' to type 'LogicValue'

我评论了下面代码中导致问题的那一行.

这是一切:

// This function returns the path to the Documents folder:
func pathToDocsFolder() -> String {
    let pathToDocumentsFolder = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as String

    return pathToDocumentsFolder.stringByAppendingPathComponent("/moviesDataBase.sqlite")
}


override func viewDidLoad() {
    super.viewDidLoad()

    let theFileManager = NSFileManager.defaultManager()

    if theFileManager.fileExistsAtPath(pathToDocsFolder()) {
        println("File Found!")
        // And then open the DB File
    }
    else {
        // Copy the file from the Bundle and write it to the Device:
        let pathToBundledDB = NSBundle.mainBundle().pathForResource("moviesDB", ofType: …
Run Code Online (Sandbox Code Playgroud)

bundle nsfilemanager swift

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

Swift SequenceType不起作用

我正在尝试实现SequenceType/GeneratorType示例并获得一个不太有意义的错误.

这是代码:

// Here's my GeneratorType - it creates a random-number Generator:
struct RandomNumberGenerator:GeneratorType {
    typealias Element = Int
    mutating func next() -> Element? {
       return Int(arc4random_uniform(100))
    }
} 
Run Code Online (Sandbox Code Playgroud)

当我打电话给它(在Playgrounds中)时,它的效果非常好:

var randyNum = RandomNumberGenerator()
randyNum.next()   // this shows a valid random number in the Gutter
// And calling it from within a println also works:
println("randyNum = \(randyNum.next()!)")
Run Code Online (Sandbox Code Playgroud)

到目前为止一切都那么好.

接下来是SequenceType:

struct RandomNumbersSequence:SequenceType {
    typealias Generator = RandomNumberGenerator
    var numberOfRandomNumbers:Int

    init(maxNum:Int) {
        numberOfRandomNumbers = maxNum
    }

    func generate() -> Generator { …
Run Code Online (Sandbox Code Playgroud)

foreach generator sequence for-in-loop swift

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

在 Swift 中子类化 UINavigationBar

我正在尝试创建一个自定义UINavigationBar类,然后使用将其设置为我的 NavigationBar 的Storyboard类。UINavigationController

这是我的班级的代码UINavigationBar

class CustomNavBar: UINavigationBar {

    override func drawRect(rect: CGRect) {
        super.drawRect(rect)
        // Drawing code
        self.backgroundColor = UIColor.orangeColor()

        let myLabel = UILabel(frame: CGRect(x: 0, y: 4, width: 600, height: 36))
        myLabel.backgroundColor = UIColor.purpleColor()
        myLabel.textColor = UIColor.yellowColor()
        myLabel.text = "Custom NavBar!"

        self.addSubview(myLabel)
    }

}
Run Code Online (Sandbox Code Playgroud)

然后,在 Interface Builder 中,我使用 将Identity Inspector其设置为NavigationBar我的UINavigationController.

当我运行该应用程序时 - 它冻结了。它挂起LaunchScreen.xib并且不执行任何操作。

为什么要这么做?这样做的正确方法是什么?

subclass uinavigationbar uinavigationcontroller ios swift

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

Swift Dictionaries:不可能让一个数组成为一个键的价值吗?

我想声明几个数组并将它们指定为字典中键的值.

这是代码:

class ViewController: UIViewController {
   let colorsArray = ["Blue", "Red", "Green", "Yellow"]
   let numbersArray = ["One", "Two", "Three", "Four"]

   let myDictionary = ["Colors" : colorsArray, "Numbers" : numbersArray]

   override func viewDidLoad() {
        super.viewDidLoad()
        // etc.
Run Code Online (Sandbox Code Playgroud)

这会产生以下错误:

ViewController.Type does not have a member named 'colorsArray'
Run Code Online (Sandbox Code Playgroud)



所以....

我尝试修改我的字典声明,如下所示:

let myDictionary:Dictionary<String, Array> = ["Colors" : colorsArray, "Numbers" : numbersArray]
Run Code Online (Sandbox Code Playgroud)

这给了我一个更好的错误:

Reference to generic type 'Array' requires arguments in <...>
Run Code Online (Sandbox Code Playgroud)


我尝试了各种其他修复 - 没有任何作用.

这在Objective-C中是小菜一碟,但在Swift ......?

解决方案:
将字典声明语句移动到viewDidLoad固定它:

class …
Run Code Online (Sandbox Code Playgroud)

arrays dictionary swift

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

在PHP文件中将密码隐藏到MySQL数据库的问题

我有一个带有表单的HTML文件,一旦用户点击"提交",就会调用一个PHP文件,该文件连接到MySQL数据库并使用表单中的数据进行更新.

问题是,如何在PHP代码文件中屏蔽/隐藏MySQL数据库的密码?

我正在阅读有关使用"配置"文件和/或将事物移动到不同目录中的各种事情,以防止其他人访问它们 - 我理论上得到它 - 但我应该采取的实际步骤是什么实现这一目标?我喜欢从哪里开始?步骤#1是什么,步骤#2是什么?每个人似乎都提供了很少的代码片段,但我还没有找到任何好的从头到尾的教程.

我打电话给GoDaddy--我的帐户和数据库所在的位置 - 看看他们的技术支持人员是否可以提供帮助 - 没有人能够告诉我究竟要做什么,从哪里开始等等.

任何人都可以帮忙吗?

php mysql connection securestring

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

UIView类别 - 不返回UIView的自定义方法

我在UIView上创建了一个类别,其方法是创建和返回UIView对象.它运行没有错误但返回一个空的UIView.这是代码:

#import <UIKit/UIKit.h>

@interface UIView (makeTableHeader)


 -(UIView *) makeTableHeader:(NSString *)ImageName
                  withTitle:(NSString *)headerTitle
                  usingFont:(NSString *)fontName 
                andFontSize:(CGFloat)fontSize;


@end
Run Code Online (Sandbox Code Playgroud)

这是实施:

-(UIView *) makeTableHeader: (NSString *)ImageName 
              withTitle:(NSString *)headerTitle 
              usingFont:(NSString *)fontName 
            andFontSize:(CGFloat)fontSize {

     // Create a master-view:
     UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 34)];

     // Create the Image:
     UIImageView *headerImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:ImageName]];
     headerImageView.frame = CGRectMake(0, 0, 320, 34);


     // Now create the Header LABEL:
     UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 34)];
     headerLabel.text = headerTitle;
     headerLabel.font = [UIFont fontWithName:fontName …
Run Code Online (Sandbox Code Playgroud)

iphone uitableview uiview categories

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

UIBarButtonItem未显示在UINavigationController中

我正在尝试向UINavigationController的导航栏添加2个按钮:

1)左侧的标准"后退"按钮 - 工作,和

2)右侧的"搜索"按钮 - 不显示.

这是代码:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

// 1st button - this shows up correctly:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
backButton.title = @"MAIN";
self.navigationItem.backBarButtonItem = backButton;    

// 2nd. button - this one does not show up:
UIBarButtonItem *searchButton = [[UIBarButtonItem alloc]
                                           initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
                                           target:self
                                           action:@selector(goSearching:)];
self.navigationItem.rightBarButtonItem = searchButton;


itemsByTitleVC *itemsView = [[itemsByTitleVC alloc] initWithNibName:@"itemsByTitleVC" bundle:nil];


[self.navigationController pushViewController:itemsView animated:YES];
Run Code Online (Sandbox Code Playgroud)

}

谁知道为什么这不起作用?(对于它的价值,我正在使用Xcode 4.2,使用Storyboard ......)

iphone uinavigationcontroller rightbarbuttonitem uinavigationitem

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

mysqli插入 - 但只有不重复

我是一名Java开发人员,他只是接受了"一些快速简单的DB内容"的任务 - 除了我对PHP/MySQL不太了解...我需要在数据库中插入一条记录 - 但仅限于电子邮件字段与DB中已存在的字段不匹配.这是我到目前为止为我的PHP代码收集的内容:

// Grab the values from the HTML form:
$newUserName = $_POST['newUserName'];
$newUserName = $mysqli->real_escape_string($newUserName);
$newUserEmail = $_POST['newUserEmail'];
$newUserEmail = $mysqli->real_escape_string($newUserEmail);

// Now search the DB to see if a record with this email already exists:
$mysqli->query("SELECT * FROM RegisteredUsersTable WHERE UserEmail = '$newUserEmail'");
Run Code Online (Sandbox Code Playgroud)

现在我需要查看是否有任何内容从该搜索返回 - 这意味着电子邮件已经存在 - 如果是这样,我需要提醒用户,否则我可以继续使用以下内容将新信息插入到数据库中:

$mysqli->query("INSERT INTO RegisteredUsersTable (UserName, UserEmail) VALUES ('".$newUserName."', '".$newUserEmail."')");
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

php mysql search mysqli insert

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

iOS 6在设备轮换时崩溃

这不是一个重复的问题.尚未提供最终工作解决方案.在我接受答案或找到并提供我自己的解决方案之前,请不要关闭此问题.谢谢!

================================================== ================使用Xcode 4.5.1,我有一个标签栏应用程序,里面有5个标签.每个选项卡都包含一个UINavigationController.因此,整个应用程序需要在纵向模式下查看,除了一个唯一的ViewController - 一个"模态"VC,它以全屏模式打开,并且打算在横向模式下查看.

这在iOS5中运行得非常好 - 我只是在一个特定的ViewController中使用了以下代码:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
Run Code Online (Sandbox Code Playgroud)

但现在应用程序崩溃了,并给出了这个错误:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation',    
reason: 'preferredInterfaceOrientationForPresentation must return a supported interface orientation!'
Run Code Online (Sandbox Code Playgroud)

有什么建议?

iphone orientation device-orientation ios6

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